Knex - Already up to date - node.js

I am struggling with a problem connected with the migrations in knex on the production environment (heroku). I have made some changes and created 8 new migrations to update the model. After creating new migrations I have reached 47 migration files. After uploading the changes to the Heroku I executed as usual knex migrate:latest and there was no effect. I have received the message Already up to date.
I have decided to take a look at the knex_migrations table to see if maybe something is wrong there. The result that I can see that the new migrations were not written into that database (please see the picture for reference.
When we take a look at the migrations it looks like this:
Clearly we can see that knex was able to run "20200216191040_receiver_company.js" as last one.
When I take a look at the knex_migrations_lock table the only entry that is existing over there looks like this:
Does anyone know how to force knex to run the migrations? The version of knex that I use it 0.16.3.
EDIT:
I want to add that on the local machine I have no problems with running the migrations. Additionally, I have checked if the migration files are present on the server and after pulling the current state our of the Heroku I can see all of the migration files that were not executed.

If the change of the migration is not implemented in the database, you can try to manually remove the record of the migration from the knex_migrations or you migrations table,
and try to re-apply the knex migrate:latest command.
but before you try this way, make sure to keep a backup, or run it on your local machine or development server first.

Related

Prisma cause data lost when i run migration

I am using prisma with data pipeline. i am fetching data from different database and create new portal with few changes in database. Database can also change in production time, i don't want to lose ant data from data factory. is it possible to run migration without cause data lost.
You have to use prisma migrate resolve in order to ignore some migrations before running prisma migrate deploy, here you go more information

Commiting a SQL db to github?

Possibly newbie question.
I made an app (Postgres, Node, React) and I want to send it to somebody who can try it out with this little db that I made for it. Is there a way to do that? Googling has brought up a few seemingly positive results but none of them I've been able to apply to my application. Is there a resource I can look into (OS, VS environment)?
Like crimson589's comment you can create a db dump with all the sql used to create the database
pg_dump dbname > outfile
https://www.postgresql.org/docs/9.1/backup-dump.html
commit outfile to git or other version control
If you want to use github, create a repo via the web and it tells you how to add your code to the repo.

Fails with preceeding/existing migrations

When creating a second migration and attempting to migrate up to add it, the task fails because the first migration was already run. It seems to be running (and failing) rather than skipping previously successful/complete migrations.
I have tried with --no-check-order but I don't want to do that everytime I got new migrations to add.
I have my database locally.
Using node-pg-migrate and postgreSQL
In a general way, the order of migrations matters as you can e.g. alter the same type and the last run migration wins.
It can happen e.g. if you have pull requests and merge them to base branch in a different order than the migrations were created.
You can now e.g. rename migration so it is sorted on disk in the correct order (before not-run-migrations) and update records in pgmigrations table, or you can put new migrations aside (so they do not trigger this error) and run as many down migrations as needed, then restore migrations definitions on disk and run up migrations.

JHipster resolve conflicts after upgrading an app

for the first time I updated an app with the jhipster upgrade command.
It seems all ok but at the end of the updating it noticed me about three conflicts that I have to resolve manually.
My first problem is: how to update the Liquibase scripts?
In this case, have been added some uniqueConstraintName but I can't to add them in my scripts because they have already been executed.
So, which is the best solution? Don't update the scripts? Mark them as merged? Add manually another script in order to add these constraints?
And how I have to solve other conflicts like the image below?
Simply copy and paste from new file to old file?
Thanks a lot,
Andrea
If you have a live database, then you must not upgrade your liquibase scripts but add new ones to do the migration. What you can do is running the new scripts against a blank dev database (same type of db as prod), then revert to old scripts, then call ./mvnw liquibase:diff to get the delta script, then add the delta script to the scripts to run.

How to deploy changes for postgres with NodeJs?

I have a nodeJS app with PostgreSQL database.
I've modified source code, and now, to deploy it i'll need to deploy source code to server from git repo. Changes will be applied, server will be restarted and that's all.
Is there similar approach for deploying Postgres changes? Or i'll always need to manually write bunch of queries, which will modify database schema?

Resources