-
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
Lucas Bozzo
authored and
Lucas Bozzo
committed
Apr 28, 2024
1 parent
4cf4aa1
commit ae216ee
Showing
7 changed files
with
81 additions
and
2 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 |
---|---|---|
@@ -0,0 +1,20 @@ | ||
name: Migrate DB | ||
|
||
on: | ||
push: | ||
branches: | ||
- main | ||
|
||
jobs: | ||
migrate: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v4 | ||
- uses: actions/setup-node@v4 | ||
with: | ||
node-version: 20 | ||
cache: 'npm' | ||
- run: npm ci | ||
- run: npm test | ||
- run: npm run db:generate | ||
- run: npm run db:migrate |
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 |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import type { Config } from 'drizzle-kit'; | ||
import * as dotenv from 'dotenv'; | ||
dotenv.config({ path: '.dev.vars' }); | ||
|
||
export default { | ||
schema: './src/data/schema.ts', | ||
out: 'migrations', | ||
driver: 'turso', | ||
dbCredentials: { | ||
url: process.env.TURSO_DATABASE_URL!, | ||
authToken: process.env.TURSO_AUTH_TOKEN, | ||
}, | ||
} 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,21 @@ | ||
{ | ||
"scripts": { | ||
"dev": "wrangler dev src/index.ts", | ||
"deploy": "wrangler deploy --minify src/index.ts" | ||
"deploy": "wrangler deploy --minify src/index.ts", | ||
"db:generate": "drizzle-kit generate:sqlite", | ||
"db:push": "drizzle-kit push:sqlite", | ||
"db:migrate": "tsx ./src/data/migrate.ts", | ||
"db:studio": "drizzle-kit studio" | ||
}, | ||
"dependencies": { | ||
"@libsql/client": "^0.6.0", | ||
"drizzle-orm": "^0.30.9", | ||
"hono": "^4.2.8" | ||
}, | ||
"devDependencies": { | ||
"@cloudflare/workers-types": "^4.20240403.0", | ||
"dotenv": "^16.4.5", | ||
"drizzle-kit": "^0.20.17", | ||
"wrangler": "^3.47.0" | ||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import { drizzle } from 'drizzle-orm/libsql'; | ||
import { createClient } from '@libsql/client/web'; | ||
|
||
const turso = createClient({ | ||
url: process.env.TURSO_DATABASE_URL!, | ||
authToken: process.env.TURSO_AUTH_TOKEN, | ||
}); | ||
|
||
export const data = drizzle(turso); |
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 |
---|---|---|
@@ -0,0 +1,22 @@ | ||
// migrate.ts | ||
|
||
import { config } from 'dotenv'; | ||
import { migrate } from 'drizzle-orm/libsql/migrator'; | ||
import { data } from './index'; | ||
|
||
config({ path: '.dev.vars' }); | ||
|
||
const main = async () => { | ||
try { | ||
console.log('Running migrations'); | ||
await migrate(data, { migrationsFolder: 'migrations' }); | ||
console.log('Migration complete!'); | ||
} catch (error) { | ||
console.error('Migration failed'); | ||
console.error(error); | ||
process.exit(1); | ||
} | ||
process.exit(0); | ||
}; | ||
|
||
main(); |
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 |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import { sql } from 'drizzle-orm'; | ||
import { text, sqliteTable } from 'drizzle-orm/sqlite-core'; | ||
|
||
export const foo = sqliteTable('foo', { | ||
bar: text('bar').notNull().default('Hey!'), | ||
baz: text('baz').notNull().default('Hello World!'), | ||
}); |
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