feat: add basic webui
This commit is contained in:
3
packages/migrate/.gitignore
vendored
Normal file
3
packages/migrate/.gitignore
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
node_modules
|
||||
# Keep environment variables out of version control
|
||||
.env
|
||||
83
packages/migrate/index.ts
Normal file
83
packages/migrate/index.ts
Normal file
@@ -0,0 +1,83 @@
|
||||
import {
|
||||
buildAuth,
|
||||
getAuthMigrations,
|
||||
} from '@konobangu/auth/better-auth.config';
|
||||
import { buildDatabase, buildMigrator } from '@konobangu/database/builder';
|
||||
|
||||
export const up = async (envVars: Record<string, any>) => {
|
||||
const { db, pool } = buildDatabase(envVars.DATABASE_URL);
|
||||
|
||||
const authConfig = buildAuth({ pool, baseURL: envVars.NEXT_PUBLIC_APP_URL });
|
||||
|
||||
const { toBeAdded, toBeCreated, runMigrations } = await getAuthMigrations(
|
||||
authConfig.options
|
||||
);
|
||||
|
||||
if (!toBeAdded.length && !toBeCreated.length) {
|
||||
// biome-ignore lint/suspicious/noConsole: <explanation>
|
||||
console.info('No auth migrations needed.');
|
||||
process.exit(0);
|
||||
}
|
||||
|
||||
// biome-ignore lint/suspicious/noConsole: <explanation>
|
||||
console.info('Migrating auth...');
|
||||
|
||||
await runMigrations();
|
||||
|
||||
// biome-ignore lint/suspicious/noConsole: <explanation>
|
||||
console.info('Auth migration was completed successfully!');
|
||||
|
||||
// biome-ignore lint/suspicious/noConsole: <explanation>
|
||||
console.info('Migrating webui...');
|
||||
|
||||
const { error, results } = await buildMigrator(db).migrateUp();
|
||||
|
||||
for (const it of results || []) {
|
||||
if (it.status === 'Success') {
|
||||
// biome-ignore lint/suspicious/noConsole: <explanation>
|
||||
// biome-ignore lint/suspicious/noConsoleLog: <explanation>
|
||||
console.log(
|
||||
`migration up "${it.migrationName}" was executed successfully`
|
||||
);
|
||||
} else if (it.status === 'Error') {
|
||||
// biome-ignore lint/suspicious/noConsole: <explanation>
|
||||
console.error(`failed to execute migration up "${it.migrationName}"`);
|
||||
}
|
||||
}
|
||||
|
||||
if (error) {
|
||||
// biome-ignore lint/suspicious/noConsole: <explanation>
|
||||
console.error('failed to migrate up');
|
||||
// biome-ignore lint/suspicious/noConsole: <explanation>
|
||||
console.error(error);
|
||||
|
||||
process.exit(1);
|
||||
}
|
||||
};
|
||||
|
||||
export const down = async (envVars: Record<string, any>) => {
|
||||
const { db } = buildDatabase(envVars.DATABASE_URL);
|
||||
|
||||
const { error, results } = await buildMigrator(db).migrateDown();
|
||||
|
||||
for (const it of results || []) {
|
||||
if (it.status === 'Success') {
|
||||
// biome-ignore lint/suspicious/noConsoleLog: <explanation>
|
||||
// biome-ignore lint/suspicious/noConsole: <explanation>
|
||||
console.log(
|
||||
`migration down "${it.migrationName}" was executed successfully`
|
||||
);
|
||||
} else if (it.status === 'Error') {
|
||||
// biome-ignore lint/suspicious/noConsole: <explanation>
|
||||
console.error(`failed to execute migration down "${it.migrationName}"`);
|
||||
}
|
||||
}
|
||||
|
||||
if (error) {
|
||||
// biome-ignore lint/suspicious/noConsole: <explanation>
|
||||
console.error('failed to migrate down');
|
||||
// biome-ignore lint/suspicious/noConsole: <explanation>
|
||||
console.error(error);
|
||||
process.exit(1);
|
||||
}
|
||||
};
|
||||
22
packages/migrate/package.json
Normal file
22
packages/migrate/package.json
Normal file
@@ -0,0 +1,22 @@
|
||||
{
|
||||
"name": "@konobangu/migrate",
|
||||
"version": "0.0.0",
|
||||
"main": "./index.ts",
|
||||
"types": "./index.ts",
|
||||
"scripts": {
|
||||
"clean": "git clean -xdf .cache .turbo dist node_modules",
|
||||
"typecheck": "tsc --noEmit --emitDeclarationOnly false"
|
||||
},
|
||||
"dependencies": {
|
||||
"@konobangu/env": "workspace:*",
|
||||
"@konobangu/auth": "workspace:*",
|
||||
"@konobangu/database": "workspace:*",
|
||||
"@next/env": "^15.1.3"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@konobangu/typescript-config": "workspace:*",
|
||||
"@types/node": "22.10.1",
|
||||
"bufferutil": "^4.0.8",
|
||||
"typescript": "^5.7.2"
|
||||
}
|
||||
}
|
||||
12
packages/migrate/scripts/down.ts
Normal file
12
packages/migrate/scripts/down.ts
Normal file
@@ -0,0 +1,12 @@
|
||||
import { loadEnvConfig } from '@next/env';
|
||||
import { down } from '../index';
|
||||
|
||||
async function main() {
|
||||
loadEnvConfig(process.cwd());
|
||||
|
||||
const { env } = await import('@konobangu/env');
|
||||
|
||||
await down(env);
|
||||
}
|
||||
|
||||
main();
|
||||
12
packages/migrate/scripts/up.ts
Normal file
12
packages/migrate/scripts/up.ts
Normal file
@@ -0,0 +1,12 @@
|
||||
import { loadEnvConfig } from '@next/env';
|
||||
import { up } from '../index';
|
||||
|
||||
async function main() {
|
||||
loadEnvConfig(process.cwd());
|
||||
|
||||
const { env } = await import('@konobangu/env');
|
||||
|
||||
await up(env);
|
||||
}
|
||||
|
||||
main();
|
||||
8
packages/migrate/tsconfig.json
Normal file
8
packages/migrate/tsconfig.json
Normal file
@@ -0,0 +1,8 @@
|
||||
{
|
||||
"extends": "@konobangu/typescript-config/react-library.json",
|
||||
"compilerOptions": {
|
||||
"baseUrl": "."
|
||||
},
|
||||
"include": ["**/*.ts", "**/*.tsx"],
|
||||
"exclude": ["node_modules"]
|
||||
}
|
||||
Reference in New Issue
Block a user