K
Kysely10mo ago
Saif

Is there a way to handle migrations with .sql files?

I enjoy being able to control the specific queries in the migration files. To do this, I use postgrator (https://www.npmjs.com/package/postgrator) along with a custom script that also manages which environment should run each file. Does Kysely migrations also support this feature (migrations with only .sql files)?
-- context: dev,stage,prod
CREATE TABLE IF NOT EXISTS postgrator_migrations (
version BIGINT NOT NULL,
name TEXT NULL,
md5 TEXT NULL,
run_at TIMESTAMP WITH TIME ZONE NULL,
CONSTRAINT postgrator_migrations_pkey PRIMARY KEY (version)
);
-- context: dev,stage,prod
CREATE TABLE IF NOT EXISTS postgrator_migrations (
version BIGINT NOT NULL,
name TEXT NULL,
md5 TEXT NULL,
run_at TIMESTAMP WITH TIME ZONE NULL,
CONSTRAINT postgrator_migrations_pkey PRIMARY KEY (version)
);
npm
postgrator
A SQL migration tool for SQL people. Latest version: 7.2.0, last published: 7 months ago. Start using postgrator in your project by running npm i postgrator. There are 37 other projects in the npm registry using postgrator.
No description
Solution:
But nothing prevents you from using a separate tool for migrations. There's no benefit from using Kysely's migrations. And to be honest, the migration module has received very little love. It's quite bare-bones.
Jump to solution
2 Replies
koskimas
koskimas10mo ago
You can implement your own MigrationProvider. The interface is dead-simple: https://kysely-org.github.io/kysely-apidoc/interfaces/MigrationProvider.html You can execute the raw SQL you read from a file using sql.raw(theSql).execute(db).
MigrationProvider | kysely
Documentation for kysely
Solution
koskimas
koskimas10mo ago
But nothing prevents you from using a separate tool for migrations. There's no benefit from using Kysely's migrations. And to be honest, the migration module has received very little love. It's quite bare-bones.
Want results from more Discord servers?
Add your server