Skip to content

Commit 0fdfbda

Browse files
committed
Add drizzle seed
1 parent fce11ff commit 0fdfbda

7 files changed

Lines changed: 535 additions & 232 deletions

File tree

apps/www/package.json

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,21 +21,22 @@
2121
"db:migrate:local": "pnpm db:migrate -- --local"
2222
},
2323
"devDependencies": {
24-
"@cloudflare/workers-types": "4.20250812.0",
24+
"@cloudflare/workers-types": "4.20250813.0",
2525
"@eslint/compat": "^1.3.2",
2626
"@eslint/js": "^9.33.0",
2727
"@faker-js/faker": "9.9.0",
2828
"@playwright/test": "1.54.2",
2929
"@sveltejs/adapter-cloudflare": "7.1.3",
3030
"@sveltejs/kit": "2.28.0",
31-
"@sveltejs/vite-plugin-svelte": "6.1.1",
31+
"@sveltejs/vite-plugin-svelte": "6.1.2",
3232
"@tailwindcss/forms": "0.5.10",
3333
"@tailwindcss/typography": "0.5.16",
3434
"@tailwindcss/vite": "^4.1.11",
3535
"@types/eslint": "9.6.1",
36-
"@types/node": "^24.2.1",
36+
"@types/node": "^22.14.1",
3737
"@types/react": "19.1.10",
3838
"drizzle-kit": "0.31.4",
39+
"drizzle-seed": "^0.3.1",
3940
"eslint": "9.33.0",
4041
"eslint-config-prettier": "10.1.8",
4142
"eslint-plugin-svelte": "3.11.0",
@@ -46,12 +47,12 @@
4647
"svelte": "5.38.1",
4748
"svelte-check": "4.3.1",
4849
"tailwindcss": "4.1.11",
49-
"tsx": "4.20.3",
50+
"tsx": "4.20.4",
5051
"typescript": "5.8.3",
51-
"typescript-eslint": "8.38.0",
52+
"typescript-eslint": "8.39.1",
5253
"vite": "7.1.2",
5354
"vitest": "2.1.8",
54-
"wrangler": "4.28.1"
55+
"wrangler": "4.29.1"
5556
},
5657
"dependencies": {
5758
"@lucia-auth/adapter-drizzle": "1.1.0",
@@ -68,12 +69,12 @@
6869
"clsx": "2.1.1",
6970
"date-fns": "4.1.0",
7071
"drizzle-orm": "0.44.4",
71-
"groq": "4.3.0",
72+
"groq": "4.4.0",
7273
"lucia": "3.2.2",
7374
"marked": "16.1.2",
7475
"nanoid": "5.1.5",
7576
"react": "19.1.1",
76-
"resend": "4.7.0",
77+
"resend": "6.0.1",
7778
"svelte-sonner": "1.0.5",
7879
"tailwind-merge": "3.3.1",
7980
"zod": "4.0.17",

apps/www/scripts/seed.ts

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
/* eslint-disable @typescript-eslint/no-explicit-any */
2+
import { setup } from './setup';
3+
import * as schema from '../src/lib/db/schemas';
4+
import { seed } from 'drizzle-seed';
5+
import { BaseSQLiteDatabase } from 'drizzle-orm/sqlite-core';
6+
import { ExtractTablesWithRelations } from 'drizzle-orm';
7+
8+
async function main() {
9+
const { db } = await setup();
10+
await seed(
11+
db as unknown as BaseSQLiteDatabase<
12+
any,
13+
any,
14+
Record<string, never>,
15+
ExtractTablesWithRelations<Record<string, never>>
16+
>,
17+
schema
18+
);
19+
}
20+
21+
main()
22+
.then(() => {
23+
process.exit(0);
24+
})
25+
.catch((err) => {
26+
console.error(err);
27+
process.exit(1);
28+
});

apps/www/src/lib/db/schemas/claimed-credit.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,13 @@ import { users } from './users';
33
import type { InferSelectModel, InferInsertModel } from 'drizzle-orm';
44

55
export const claimedCredits = sqliteTable('claimed_credits', {
6-
id: text('id').primaryKey(),
7-
userId: text('user_id')
6+
id: text().primaryKey(),
7+
userId: text()
88
.notNull()
99
.references(() => users.id),
10-
productId: text('product_id').notNull(),
11-
creditCost: integer('credit_cost').notNull(),
12-
createdAt: integer('created_at', { mode: 'timestamp' })
10+
productId: text().notNull(),
11+
creditCost: integer().notNull(),
12+
createdAt: integer({ mode: 'timestamp' })
1313
.notNull()
1414
.$defaultFn(() => new Date())
1515
});

apps/www/src/lib/db/schemas/groups.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@ import type { InferInsertModel, InferSelectModel } from 'drizzle-orm';
22
import { sqliteTable, text } from 'drizzle-orm/sqlite-core';
33

44
export const groups = sqliteTable('group', {
5-
id: text('id').primaryKey(),
6-
name: text('name').notNull(),
7-
description: text('description')
5+
id: text().primaryKey(),
6+
name: text().notNull(),
7+
description: text()
88
});
99

1010
export type Group = InferSelectModel<typeof groups>;

apps/www/src/lib/db/schemas/notifications.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,16 @@ import { users } from './users';
66
export const notifications = sqliteTable(
77
'notification',
88
{
9-
id: text('id').primaryKey().$defaultFn(nanoid),
10-
userId: text('user_id')
9+
id: text().primaryKey().$defaultFn(nanoid),
10+
userId: text()
1111
.notNull()
1212
.references(() => users.id, {
1313
onDelete: 'cascade'
1414
}),
15-
title: text('title').notNull(),
16-
body: text('body'),
17-
archivedAt: integer('archived_at', { mode: 'timestamp' }),
18-
createdAt: integer('created_at', { mode: 'timestamp' })
15+
title: text().notNull(),
16+
body: text(),
17+
archivedAt: integer({ mode: 'timestamp' }),
18+
createdAt: integer({ mode: 'timestamp' })
1919
.notNull()
2020
.$defaultFn(() => new Date())
2121
},

apps/www/src/lib/db/schemas/users-groups.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,12 @@ import { users } from './users';
44
import { relations, type InferInsertModel, type InferSelectModel } from 'drizzle-orm';
55

66
export const usersGroups = sqliteTable('users_groups', {
7-
userId: text('user_id')
7+
userId: text()
88
.notNull()
99
.references(() => users.id, {
1010
onDelete: 'cascade'
1111
}),
12-
groupId: text('group_id')
12+
groupId: text()
1313
.notNull()
1414
.references(() => groups.id, {
1515
onDelete: 'cascade'

0 commit comments

Comments
 (0)