mirror of
https://github.com/docmost/docmost.git
synced 2026-05-11 00:44:07 +08:00
aa143ad79c
* refactor(db): migrate from node-postgres to postgres.js * ignore schema param
30 lines
777 B
TypeScript
30 lines
777 B
TypeScript
import * as path from 'path';
|
|
import { promises as fs } from 'fs';
|
|
import { Kysely, Migrator, FileMigrationProvider } from 'kysely';
|
|
import { run } from 'kysely-migration-cli';
|
|
import * as dotenv from 'dotenv';
|
|
import { envPath, normalizePostgresUrl } from '../common/helpers';
|
|
import { PostgresJSDialect } from 'kysely-postgres-js';
|
|
import postgres from 'postgres';
|
|
|
|
dotenv.config({ path: envPath });
|
|
|
|
const migrationFolder = path.join(__dirname, './migrations');
|
|
|
|
const db = new Kysely<any>({
|
|
dialect: new PostgresJSDialect({
|
|
postgres: postgres(normalizePostgresUrl(process.env.DATABASE_URL)),
|
|
}),
|
|
});
|
|
|
|
const migrator = new Migrator({
|
|
db,
|
|
provider: new FileMigrationProvider({
|
|
fs,
|
|
path,
|
|
migrationFolder,
|
|
}),
|
|
});
|
|
|
|
run(db, migrator, migrationFolder);
|