mirror of
https://github.com/ngthanhvu/kr-phim.git
synced 2026-08-10 16:47:46 +00:00
Add database migration snapshots for comment_votes, comments, movies, and users tables
- Created 0009_snapshot.json with initial structure for comment_votes, comments, movies, and users tables. - Created 0010_snapshot.json with updated structure for comments, including new fields: pinned and spoiler. - Created 0011_snapshot.json with further updates to comments, adding anonymous field and refining existing structures.
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
import { mysqlTable, varchar, text, int, boolean, timestamp, json } from 'drizzle-orm/mysql-core'
|
||||
import { mysqlTable, varchar, text, int, boolean, timestamp, json, index } from 'drizzle-orm/mysql-core'
|
||||
|
||||
export const users = mysqlTable('users', {
|
||||
id: int('id').primaryKey().autoincrement(),
|
||||
@@ -46,7 +46,42 @@ export const movies = mysqlTable('movies', {
|
||||
updatedAt: timestamp('updated_at').notNull().defaultNow().onUpdateNow(),
|
||||
})
|
||||
|
||||
export const comments = mysqlTable('comments', {
|
||||
id: int('id').primaryKey().autoincrement(),
|
||||
userId: int('user_id').notNull(),
|
||||
source: varchar('source', { length: 50 }).notNull().default(''),
|
||||
slug: varchar('slug', { length: 500 }).notNull(),
|
||||
movieName: varchar('movie_name', { length: 500 }),
|
||||
content: text('content').notNull(),
|
||||
parentId: int('parent_id'),
|
||||
pinned: boolean('pinned').notNull().default(false),
|
||||
spoiler: boolean('spoiler').notNull().default(false),
|
||||
anonymous: boolean('anonymous').notNull().default(false),
|
||||
likeCount: int('like_count').notNull().default(0),
|
||||
dislikeCount: int('dislike_count').notNull().default(0),
|
||||
createdAt: timestamp('created_at').notNull().defaultNow(),
|
||||
updatedAt: timestamp('updated_at').notNull().defaultNow().onUpdateNow(),
|
||||
}, (table) => ({
|
||||
idxSourceSlug: index('idx_source_slug').on(table.source, table.slug),
|
||||
idxUserId: index('idx_user_id').on(table.userId),
|
||||
idxParentId: index('idx_parent_id').on(table.parentId),
|
||||
}))
|
||||
|
||||
export const commentVotes = mysqlTable('comment_votes', {
|
||||
id: int('id').primaryKey().autoincrement(),
|
||||
userId: int('user_id').notNull(),
|
||||
commentId: int('comment_id').notNull(),
|
||||
vote: int('vote').notNull(),
|
||||
createdAt: timestamp('created_at').notNull().defaultNow(),
|
||||
}, (table) => ({
|
||||
idxUserComment: index('idx_user_comment').on(table.userId, table.commentId),
|
||||
}))
|
||||
|
||||
export type User = typeof users.$inferSelect
|
||||
export type NewUser = typeof users.$inferInsert
|
||||
export type Movie = typeof movies.$inferSelect
|
||||
export type NewMovie = typeof movies.$inferInsert
|
||||
export type Comment = typeof comments.$inferSelect
|
||||
export type NewComment = typeof comments.$inferInsert
|
||||
export type CommentVote = typeof commentVotes.$inferSelect
|
||||
export type NewCommentVote = typeof commentVotes.$inferInsert
|
||||
|
||||
Reference in New Issue
Block a user