Skip to content

Commit cdc38f7

Browse files
committed
update content
Signed-off-by: Kirill Mokevnin <[email protected]>
1 parent bfa9469 commit cdc38f7

File tree

21 files changed

+1352
-52
lines changed

21 files changed

+1352
-52
lines changed

db/schema.js

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { sql } from 'drizzle-orm'
12
import {
23
text,
34
integer,
@@ -8,4 +9,28 @@ export const users = sqliteTable('users', {
89
id: integer('id').primaryKey(),
910
fullName: text('full_name'),
1011
email: text('email').notNull().unique(),
12+
updatedAt: text('updated_at'),
13+
createdAt: text('created_at')
14+
.notNull()
15+
.default(sql`(unixepoch())`),
16+
})
17+
18+
export const courses = sqliteTable('courses', {
19+
id: integer('id').primaryKey(),
20+
name: text('name'),
21+
creatorId: integer('creator_id').references(() => users.id),
22+
description: text('description').notNull(),
23+
createdAt: text('created_at')
24+
.notNull()
25+
.default(sql`(unixepoch())`),
26+
})
27+
28+
export const courseLessons = sqliteTable('course_lessons', {
29+
id: integer('id').primaryKey(),
30+
name: text('name'),
31+
courseId: integer('courseId').references(() => courses.id).notNull(),
32+
body: text('body').notNull(),
33+
createdAt: text('created_at')
34+
.notNull()
35+
.default(sql`(unixepoch())`),
1136
})

db/seeds.js

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,20 @@
11
import { faker } from '@faker-js/faker'
22

33
import * as schemas from './schema.js'
4+
import { buildCourse, buildCourseLesson, buildUser } from '../lib/data.js'
45
/**
56
* @param {import("drizzle-orm/better-sqlite3").BetterSQLite3Database<typeof schemas>} db
67
*/
78
export default async (db) => {
8-
await db.insert(schemas.users).values(
9-
{
10-
email: faker.internet.email(),
11-
fullName: faker.person.fullName(),
12-
},
9+
const [user1] = await db.insert(schemas.users).values(buildUser()).returning()
10+
const [user2] = await db.insert(schemas.users).values(buildUser()).returning()
11+
const [course1] = await db.insert(schemas.courses).values(
12+
buildCourse({ creatorId: user2.id }),
13+
).returning()
14+
const [course2] = await db.insert(schemas.courses).values(
15+
buildCourse({ creatorId: user2.id }),
16+
).returning()
17+
await db.insert(schemas.courseLessons).values(
18+
buildCourseLesson({ courseId: course2.id }),
1319
)
1420
}

drizzle/0000_stormy_forgotten_one.sql

Lines changed: 0 additions & 7 deletions
This file was deleted.

drizzle/0000_striped_mephisto.sql

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
CREATE TABLE `course_lessons` (
2+
`id` integer PRIMARY KEY NOT NULL,
3+
`name` text,
4+
`courseId` integer NOT NULL,
5+
`body` text NOT NULL,
6+
`created_at` text DEFAULT (unixepoch()) NOT NULL,
7+
FOREIGN KEY (`courseId`) REFERENCES `courses`(`id`) ON UPDATE no action ON DELETE no action
8+
);
9+
--> statement-breakpoint
10+
CREATE TABLE `courses` (
11+
`id` integer PRIMARY KEY NOT NULL,
12+
`name` text,
13+
`creator_id` integer,
14+
`description` text NOT NULL,
15+
`created_at` text DEFAULT (unixepoch()) NOT NULL,
16+
FOREIGN KEY (`creator_id`) REFERENCES `users`(`id`) ON UPDATE no action ON DELETE no action
17+
);
18+
--> statement-breakpoint
19+
CREATE TABLE `users` (
20+
`id` integer PRIMARY KEY NOT NULL,
21+
`full_name` text,
22+
`email` text NOT NULL,
23+
`updated_at` text,
24+
`created_at` text DEFAULT (unixepoch()) NOT NULL
25+
);
26+
--> statement-breakpoint
27+
CREATE UNIQUE INDEX `users_email_unique` ON `users` (`email`);

drizzle/meta/0000_snapshot.json

Lines changed: 134 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,127 @@
11
{
22
"version": "6",
33
"dialect": "sqlite",
4-
"id": "aa587fca-e182-4e52-9c64-fdccc3b58d8f",
4+
"id": "7ceb7a0a-5b91-4343-b3ae-a30bb904d647",
55
"prevId": "00000000-0000-0000-0000-000000000000",
66
"tables": {
7+
"course_lessons": {
8+
"name": "course_lessons",
9+
"columns": {
10+
"id": {
11+
"name": "id",
12+
"type": "integer",
13+
"primaryKey": true,
14+
"notNull": true,
15+
"autoincrement": false
16+
},
17+
"name": {
18+
"name": "name",
19+
"type": "text",
20+
"primaryKey": false,
21+
"notNull": false,
22+
"autoincrement": false
23+
},
24+
"courseId": {
25+
"name": "courseId",
26+
"type": "integer",
27+
"primaryKey": false,
28+
"notNull": true,
29+
"autoincrement": false
30+
},
31+
"body": {
32+
"name": "body",
33+
"type": "text",
34+
"primaryKey": false,
35+
"notNull": true,
36+
"autoincrement": false
37+
},
38+
"created_at": {
39+
"name": "created_at",
40+
"type": "text",
41+
"primaryKey": false,
42+
"notNull": true,
43+
"autoincrement": false,
44+
"default": "(unixepoch())"
45+
}
46+
},
47+
"indexes": {},
48+
"foreignKeys": {
49+
"course_lessons_courseId_courses_id_fk": {
50+
"name": "course_lessons_courseId_courses_id_fk",
51+
"tableFrom": "course_lessons",
52+
"tableTo": "courses",
53+
"columnsFrom": [
54+
"courseId"
55+
],
56+
"columnsTo": [
57+
"id"
58+
],
59+
"onDelete": "no action",
60+
"onUpdate": "no action"
61+
}
62+
},
63+
"compositePrimaryKeys": {},
64+
"uniqueConstraints": {}
65+
},
66+
"courses": {
67+
"name": "courses",
68+
"columns": {
69+
"id": {
70+
"name": "id",
71+
"type": "integer",
72+
"primaryKey": true,
73+
"notNull": true,
74+
"autoincrement": false
75+
},
76+
"name": {
77+
"name": "name",
78+
"type": "text",
79+
"primaryKey": false,
80+
"notNull": false,
81+
"autoincrement": false
82+
},
83+
"creator_id": {
84+
"name": "creator_id",
85+
"type": "integer",
86+
"primaryKey": false,
87+
"notNull": false,
88+
"autoincrement": false
89+
},
90+
"description": {
91+
"name": "description",
92+
"type": "text",
93+
"primaryKey": false,
94+
"notNull": true,
95+
"autoincrement": false
96+
},
97+
"created_at": {
98+
"name": "created_at",
99+
"type": "text",
100+
"primaryKey": false,
101+
"notNull": true,
102+
"autoincrement": false,
103+
"default": "(unixepoch())"
104+
}
105+
},
106+
"indexes": {},
107+
"foreignKeys": {
108+
"courses_creator_id_users_id_fk": {
109+
"name": "courses_creator_id_users_id_fk",
110+
"tableFrom": "courses",
111+
"tableTo": "users",
112+
"columnsFrom": [
113+
"creator_id"
114+
],
115+
"columnsTo": [
116+
"id"
117+
],
118+
"onDelete": "no action",
119+
"onUpdate": "no action"
120+
}
121+
},
122+
"compositePrimaryKeys": {},
123+
"uniqueConstraints": {}
124+
},
7125
"users": {
8126
"name": "users",
9127
"columns": {
@@ -27,6 +145,21 @@
27145
"primaryKey": false,
28146
"notNull": true,
29147
"autoincrement": false
148+
},
149+
"updated_at": {
150+
"name": "updated_at",
151+
"type": "text",
152+
"primaryKey": false,
153+
"notNull": false,
154+
"autoincrement": false
155+
},
156+
"created_at": {
157+
"name": "created_at",
158+
"type": "text",
159+
"primaryKey": false,
160+
"notNull": true,
161+
"autoincrement": false,
162+
"default": "(unixepoch())"
30163
}
31164
},
32165
"indexes": {

drizzle/meta/_journal.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
{
66
"idx": 0,
77
"version": "6",
8-
"when": 1724517819092,
9-
"tag": "0000_stormy_forgotten_one",
8+
"when": 1724697947550,
9+
"tag": "0000_striped_mephisto",
1010
"breakpoints": true
1111
}
1212
]

lib/data.js

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
import { faker } from '@faker-js/faker'
2+
import { users, courses, courseLessons } from '../db/schema.js'
3+
4+
/**
5+
* @typedef {typeof userType} UserType
6+
*/
7+
const userType = users.$inferSelect
8+
9+
/**
10+
* @typedef {typeof courseType} CourseType
11+
*/
12+
const courseType = courses.$inferSelect
13+
14+
/**
15+
* @typedef {typeof courseLessonType} CourseLessonType
16+
*/
17+
const courseLessonType = courseLessons.$inferSelect
18+
19+
/**
20+
* @param {Partial<UserType>} params
21+
*/
22+
export function buildUser(params = {}) {
23+
const user = {
24+
fullName: faker.person.fullName(),
25+
email: faker.internet.email(),
26+
}
27+
28+
return Object.assign({}, user, params)
29+
}
30+
31+
/**
32+
* @param {Partial<CourseType>} params
33+
*/
34+
export function buildCourse(params = {}) {
35+
const user = {
36+
name: faker.lorem.sentence(),
37+
description: faker.lorem.paragraph(),
38+
}
39+
40+
return Object.assign({}, user, params)
41+
}
42+
43+
/**
44+
* @param {Partial<CourseLessonType>} params
45+
*/
46+
export function buildCourseLesson(params = {}) {
47+
const lesson = {
48+
name: faker.lorem.sentence(),
49+
body: faker.lorem.paragraph(),
50+
}
51+
52+
return Object.assign({}, lesson, params)
53+
}

0 commit comments

Comments
 (0)