Skip to content

Commit

Permalink
feat: persist database
Browse files Browse the repository at this point in the history
  • Loading branch information
yamcodes committed Oct 8, 2023
1 parent fe50824 commit 8cf526c
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 16 deletions.
10 changes: 0 additions & 10 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,6 @@
"database": "medium",
"username": "postgres",
"password": "postgres"
},
{
"previewLimit": 50,
"server": "localhost",
"port": 5431,
"driver": "PostgreSQL",
"name": "myconn",
"database": "medium",
"username": "postgres",
"password": "postgres"
}
]
}
Binary file modified bun.lockb
Binary file not shown.
7 changes: 7 additions & 0 deletions db/drop.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { db } from '@/database.providers';
import { users } from '@/users/users.schema';
// TODO: add commander
console.log('Dropping the entire database');
db.delete(users);
// add more tables here
console.log('Database dropped');
8 changes: 4 additions & 4 deletions db/seed.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,16 @@ import { db } from '@/database.providers';
import { users } from '@/users/users.schema';

const data = {
id: users.id.default,
id: 1, //do not use 'users.id.default', seed should be idempotent
email: 'test@email.com',
username: 'test',
password: 'test',
bio: 'test',
image: 'test',
};
console.log('Inserting user: ', data);
await db.insert(users).values(data);
console.log('User inserted');
console.log('Upserting user: ', data);
await db.insert(users).values(data).onConflictDoNothing();
console.log('User upserted');

const userResult = await db.select().from(users);
console.log('User result: ', userResult);
Expand Down
6 changes: 4 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,16 @@
"docs:preview": "vitepress preview docs",
"up": "./scripts/create-start-container-with-env.sh",
"db:generate": "bun drizzle-kit generate:pg --config=db/config.ts",
"db:migrate": "bun run db/migrations/migrate.ts",
"db:migrate": "bun db/migrations/migrate.ts",
"db:push": "bun drizzle-kit push:pg --config=db/config.ts",
"db:seed": "bun run db/seed.ts",
"db:seed": "bun db/seed.ts",
"db:studio": "bun drizzle-kit studio --config=db/config.ts",
"db:drop": "bun db/drop.ts",
"prepare": "husky install"
},
"dependencies": {
"@elysiajs/swagger": "^0.7.3",
"commander": "^11.0.0",
"drizzle-orm": "^0.28.6",
"drizzle-typebox": "^0.1.1",
"elysia": "latest",
Expand Down

0 comments on commit 8cf526c

Please sign in to comment.