Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: make database migrations work #746

Merged
merged 2 commits into from
Aug 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .env.local.example
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,6 @@ DB_PLANETSCALE_DATABASE=planetscale
DB_PLANETSCALE_HOST=localhost:3900
DB_PLANETSCALE_USERNAME=root
DB_PLANETSCALE_PASSWORD=planetscale
DB_PLANETSCALE_DATABASE=planetscale
DB_REDIS_CONNECTION_STRING="redis://localhost:3901"


Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,17 +38,17 @@
"db:push": "dotenv -e .env.local -- pnpm --dir packages/database db:push",
"db:studio": "dotenv -e .env.local -- turbo run db:studio",
"db:generate": "dotenv -e .env.local -- turbo run db:generate",
"db:migrate": "dotenv -e .env.local -- turbo run db:migrate",
"db:up": "dotenv -e .env.local -- turbo run db:up",
"db:check": "dotenv -e .env.local -- turbo run db:generate",
"db:drop": "dotenv -e .env.local -- turbo run db:drop",
"start:all:r": "infisical run --env=remote -- turbo run start",
"dev:r": "infisical run --env=remote -- turbo run dev",
"dev:spaces": "infisical run --env=spacesremote -- turbo run dev",
"db:push:r": "infisical run --env=remote -- pnpm --dir packages/database db:push:r",
"db:push:r": "infisical run --env=remote -- pnpm --dir packages/database db:push",
"db:studio:r": "infisical run --env=remote -- turbo run db:studio",
"db:generate:r": "infisical run --env=remote -- turbo run db:generate",
"db:up:r": "infisical run --env=remote -- turbo run db:up",
"db:check:r": "infisical run --env=remote -- turbo run db:generate",
"db:drop:r": "infisical run --env=remote -- turbo run db:drop",
"ee:dev:r": "infisical run --env=remote -- turbo run ee:dev",
"ee:check": "infisical run --env=remote -- turbo run ee:check",
Expand Down
6 changes: 3 additions & 3 deletions packages/database/drizzle.config.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import type { Config } from 'drizzle-kit';
import { defineConfig } from 'drizzle-kit';
import { env } from './env';

export default {
export default defineConfig({
schema: './schema.ts',
out: './migrations',
dialect: 'mysql',
dbCredentials: {
url: env.DB_MYSQL_MIGRATION_URL
}
} satisfies Config;
});
2 changes: 0 additions & 2 deletions packages/database/env.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,5 @@ export const env = createEnv({
DB_PLANETSCALE_PASSWORD: z.string().min(1),
DB_MYSQL_MIGRATION_URL: z.string().min(1)
},
client: {},
clientPrefix: '_', // Not used, just for making TS happy
runtimeEnv: process.env
});
7 changes: 1 addition & 6 deletions packages/database/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,5 @@ const client = new Client({
}
});

const connectionOptions = {
logger: false,
schema
};

export const db = drizzle(client, connectionOptions);
export const db = drizzle(client, { schema });
export type DBType = typeof db;
7 changes: 2 additions & 5 deletions packages/database/migrate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,7 @@ import { createConnection } from 'mysql2/promise';
import { drizzle } from 'drizzle-orm/mysql2';
import { env } from './env';

const connection = await createConnection({
uri: env.DB_MYSQL_MIGRATION_URL
});
const db = drizzle(connection);

const connection = await createConnection({ uri: env.DB_MYSQL_MIGRATION_URL });
const db = drizzle(connection, { mode: 'planetscale', logger: true });
await migrate(db, { migrationsFolder: 'migrations' });
await connection.end();
Loading
Loading