SQL Migrations Not Working?
See original GitHub issueSo I know you wrote a test to test that ported sqlite migration code, saw that test in one of your commits. But when I try this in my app, it’s simply not working:
InMemoryDB.ts
const inMemoryDb = newDb();
inMemoryDb.public.none(fs.readFileSync(path.resolve(__dirname, 'migrations/001-initial.sql'), 'utf8'));
(async () =>await inMemoryDb.public.migrate())();
const skills = inMemoryDb.public.many("select * from skills where name = 'Swift'");
console.log('skills', skills); // prints []
the migrations folder is at the same level as InMemoryDB.ts and in that folder is:
001-initial.sql
002-add-skills.sql
001-initial.sql - definitely adds a skills table seeded with some initial skills
002-add-skills.sql
INSERT INTO skills VALUES ('Swift', 0);
INSERT INTO skills VALUES ('Objective-C', 0);
no idea here, thoughts?
Issue Analytics
- State:
- Created 3 years ago
- Comments:5 (2 by maintainers)
Top Results From Across the Web
sql server - Migration not working - Stack Overflow
I can't get migrations to work. When I try Add-Migration InitialCreate I get the following error: Startup project 'docker-compose' is a Docker ...
Read more >Common issues - Azure Database Migration Service
Learn about how to troubleshoot common known issues/errors associated with using Azure Database Migration Service.
Read more >SQL Migration does not run in docker · Issue #2952 - GitHub
Migrations do not automatically run when your application begins. Running dotnet App.dll will only start the web server. A separate action is ...
Read more >Code First Migrations are not applied during publish
When I publish, everything reports success, yet none of my migrations are being applied to the specified database(s). This deployment and application has...
Read more >Migrations - Django documentation
For migrations to work, you must make the initial migration first and then make changes, as Django compares changes against migration files, not...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

Tests
Some kind of building (transpiling, actually) is necessary given that it’s TS, so no, it is not possible to run mocha directly on ts files. When you do that on your side, I suppose that you’re using ts-node or something equivalent, which is transpiling TS for you. That’s also what does Webpack. Kind of an equivalent way to do the same thing.
Moreover, the current setup of pg-mem tests is using webpack because it’s way faster to code that way for me. That’s a matter of choice.
Ts compilation error
I dont see this problem on my side …
No need to read 001-initial.sql, the migration will do that for you.
Moreover, the line
(async () =>await inMemoryDb.public.migrate())();is effectively scheduling a migration, but triggers it “for later” (it dettaches a promise… use a linter, and you will get a warning on this line). Dettached promises is a pattern that should be avoided as much as possible (and which is, in this case, the cause of your problem).Thus, the 4th line is effectively executed BEFORE the migration.
This should work:
You’ll have to execute this from an async method, though.