-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
46a5791
commit fd402f6
Showing
6 changed files
with
42 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,18 @@ | ||
import 'dotenv/config' | ||
import type { Config } from 'drizzle-kit' | ||
|
||
const dbName = process.env.DB_NAME | ||
if (!dbName) { | ||
throw new Error('DB_NAME not set') | ||
const databaseUrl = process.env.DATABASE_URL | ||
const authToken = process.env.TURSO_AUTH_TOKEN | ||
if (!databaseUrl || !authToken) { | ||
throw new Error('DATABASE_URL or AUTH_TOKEN not set') | ||
} | ||
|
||
export default { | ||
out: 'src/server/database/migrations', | ||
schema: 'src/server/database/schema/*', | ||
driver: 'd1', | ||
driver: 'turso', | ||
dbCredentials: { | ||
dbName: dbName, | ||
wranglerConfigPath: 'wrangler.toml', | ||
url: databaseUrl, | ||
authToken, | ||
}, | ||
} satisfies Config |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,17 @@ | ||
import 'dotenv/config' | ||
import { migrate } from 'drizzle-orm/planetscale-serverless/migrator' | ||
import { migrate } from 'drizzle-orm/libsql/migrator' | ||
import { getDb } from '~/server/database/db' | ||
|
||
const databaseUrl = process.env.DATABASE_URL | ||
const authToken = process.env.TURSO_AUTH_TOKEN | ||
|
||
if (!databaseUrl) { | ||
if (!databaseUrl || !authToken) { | ||
throw Error('Database URL not configured in environment variable') | ||
} | ||
// This will run migrations on the database, skipping the ones already applied | ||
await migrate(getDb(databaseUrl), { | ||
migrate(getDb({ url: databaseUrl, authToken }), { | ||
migrationsFolder: './src/server/database/migrations', | ||
}).catch((err) => { | ||
console.error(err) | ||
process.exit(1) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters