Node JS db-migrate for different database - node.js

I'm already using db-migrate package to migrate MySQL database script and it works well, I've even setup the DATABASE_URL variable in the server environment.
Now I've a requirement to store few details in the sqlite in the same service, I checked db-migrate package for this feature apparently nothing mentioned regard to the executing sql scripts in multiple different databases at one go. Is it possible to do in db-migrate? or do I've to write my own service for this?

Related

How to ensure that I can only access a database while testing?

I have built an API in Node.js which communicates with a MongoDB as database. I am also using Vitest as my testing library.
I have two databases: prod and test. I want to restrict the access to the test database to only during the testing calls made due to test files ran by Vitest. Is there any way to do the same?
Proposed Solution (Maybe?)
Configure Vitest to setup an ENV flag or a NODE_ENVIRONMENT flag to TESTING whenever npm run test is called, and revert that back to DEVELOPMENT after the command is complete.
Add check while connecting to the database that if the environment is TESTING, only then connect to the test database, otherwise connect to the usual database.
The problem I am facing in this approach is configuring step 1. Any guides on the same? (Or other possible solutions to the problem?)

Does any JS library for connecting to DB support a structure in raw SQL?

Most of my dev experience is based on Ruby on Rails. The framework supports having a DB schema in two formats:
RoR DSL
SQL for cases when DSL is not enough. For instance, having an initially deffered unique constraint in PostgreSQL.
If it's needed to set up a DB from scratch, for instance in CI, it's possible to run a CLI task that will use either of the files and apply it without any further need to run migration files.
About two weeks ago we started a project that based on ExpressJS + PrismaJS and now we need to have a custom SQL for the DB structure.
After reading the Prisma docs I found that it's possible to write a custom SQL inside migration files and this is exactly what we need for our production. However, we also would like to have the same DB schema in our CI. Is there any other way to have the same schema for CI as we have in production without running migration files one by one as I can do with RoR?

Create a sqlite database to use on tests

I have a server implemented on Adonis.js with tests that perform operations against the main database. I want to use #Adonis.js/Vow and create a sqlite database dedicated only to use on the tests. The server is running on docker, and i use a docker-compose file to build the complete solution (3 servers and 2 other databases on postgreSQL). How can i create a sqlite database on docker to run it and connect to it on my tests?
Like always, the first step is to install the package from npm by running the following command.
npm i #adonisjs/lucid#alpha
Once done, run the following command to set up the package.
node ace invoke #adonisjs/lucid
1.You can choose sqlite of the available databases.
Right after the setup command is completed, we need to copy the code for validating the environment variables to the env.ts file. Since environment variables are injected from the outside, AdonisJS recommends you validate them and ensure that your app is always running with the correct set of configuration values.
The config/database.ts file holds all the configuration related to the database.
Finally, the config file relies on the environment variables and you can update them inside the .env file.
PG_HOST=localhost
PG_PORT=5432
PG_USER=root
PG_PASSWORD=
PG_DB_NAME=tests
learn more
database introduction

how to access sqlite database from node-red node?

I am creating a node-red API service that access SQLite database using SQLite node.
How to configure the database with SQLite node?
I have hard-coded db file in SQLite node.
What is the right way to develop a node-red API that access the SQLite database ?
I think I want to make the database filename configurable, so that it is fetched dynamically.
I am new to node-red programming.
If the changes are only at deploy time not runtime then you can use Environment variables as described in the doc here
If you replace the path to the DB in the config node with ${DB_PATH} then Node-RED will replace this with the value of the DB_PATH environment variable at deploy time.
Have you looked at the documentation for creation configuration nodes?
https://nodered.org/docs/creating-nodes/config-nodes

Best way to migrate table changes to production sailsjs tables

I just lost 11,000 records from my database just running the command for sailsjs without the --prod part in it, So I thought I should ask whats the best way to change the tables on production server when the Model.js has been changed ?
Thanks
Automated migration should never be done in production. This a common-sense practice that applies to any production system with important data. There are a few solutions available for migrating a sails.js database.
sails-db-migrate: db-migrate integration for sails.js
db-migrate integration for Sails.js. This is a fairly simple wrapper, which provides grunt tasks for running and creating migrations.
sails-migrations: The missing, migrations arm of the octopus
sails-migrations provides an easy way to manage database migrations with sails, based on the amazing https://github.com/tgriesser/knex lib. This means you can have fine-grained control over your schema/data transformations between versions.
Sequelize migrations
Sequelize 2.0.0 introduces a new CLI which is based on gulp and combines sequelize-cli and gulp-sequelize. The CLI ships support for migrations and project bootstrapping. With migrations you can transfer your existing database into another state and vice versa

Resources