Kysely - WIP

* create database migration files
* kysely codegen
* kysely migrate
This commit is contained in:
Philipinho
2024-03-24 16:59:26 +00:00
parent 7d56920ad5
commit d855152dda
19 changed files with 2634 additions and 643 deletions

View File

@ -0,0 +1,35 @@
import * as path from 'path';
import { promises as fs } from 'fs';
import pg from 'pg';
import {
Kysely,
Migrator,
PostgresDialect,
FileMigrationProvider,
} from 'kysely';
import { run } from 'kysely-migration-cli';
import * as dotenv from 'dotenv';
import { envPath } from '../helpers/utils';
dotenv.config({ path: envPath });
const migrationFolder = path.join(__dirname, './migrations');
const db = new Kysely<any>({
dialect: new PostgresDialect({
pool: new pg.Pool({
connectionString: process.env.DATABASE_URL,
}) as any,
}),
});
const migrator = new Migrator({
db,
provider: new FileMigrationProvider({
fs,
path,
migrationFolder,
}),
});
run(db, migrator, migrationFolder);