-
Notifications
You must be signed in to change notification settings - Fork 24
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
Showing
12 changed files
with
98 additions
and
14 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
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 |
---|---|---|
|
@@ -18,4 +18,16 @@ cli | |
} | ||
}); | ||
|
||
cli | ||
.command('database migrate', 'Migrate database') | ||
.alias('db migrate') | ||
.action(async () => { | ||
// TODO: pass options | ||
await import('dotenv/config'); | ||
const { connectDatabase, migrateDatabase } = await import('@animegarden/database'); | ||
const { connection, db } = connectDatabase(`postgres://root:[email protected]:5432/animegarden`); | ||
await migrateDatabase(db); | ||
await connection.end(); | ||
}); | ||
|
||
cli.run(process.argv.slice(2)).catch((err) => console.error(err)); |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
version: '3.9' | ||
|
||
services: | ||
postgresql: | ||
image: postgres | ||
container_name: animegarden_postgres | ||
restart: always | ||
ports: | ||
- '5432:5432' | ||
# volumes: | ||
# - ./.animegarden/database:/var/lib/postgresql/data | ||
environment: | ||
TZ: Asia/Shanghai | ||
PGTZ: Asia/Shanghai | ||
POSTGRES_DB: animegarden | ||
POSTGRES_USER: root | ||
POSTGRES_PASSWORD: example | ||
# postgres://root:[email protected]:5432/animegarden | ||
|
||
redis: | ||
image: redis | ||
container_name: animegarden_redis | ||
restart: always | ||
ports: | ||
- '6379:6379' | ||
# volumes: | ||
# - ./.animegarden/redis:/data | ||
environment: | ||
TZ: Asia/Shanghai |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import postgres from 'postgres'; | ||
import { drizzle } from 'drizzle-orm/postgres-js'; | ||
|
||
import { users } from './schema/user'; | ||
import { teams } from './schema/team'; | ||
import { resources } from './schema/resource'; | ||
|
||
export interface DatabaseConnectionConfig extends postgres.Options<{}> {} | ||
|
||
export const connectDatabase = (...args: Parameters<typeof postgres>) => { | ||
const queryClient = postgres(...args); | ||
return { | ||
connection: queryClient, | ||
db: drizzle(queryClient, { schema: { resources, users, teams } }) | ||
}; | ||
}; |
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 +1,5 @@ | ||
export * from './schema'; | ||
|
||
export * from './connection'; | ||
|
||
export * from './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,6 @@ | ||
import { migrate } from 'drizzle-orm/postgres-js/migrator'; | ||
|
||
export async function migrateDatabase(db: Parameters<typeof migrate>[0]) { | ||
const migrationsFolder = new URL('../drizzle', import.meta.url).pathname; | ||
await migrate(db, { migrationsFolder }); | ||
} |
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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