This repository was archived by the owner on Oct 17, 2025. It is now read-only.
File tree Expand file tree Collapse file tree 11 files changed +50
-31
lines changed
Expand file tree Collapse file tree 11 files changed +50
-31
lines changed Original file line number Diff line number Diff line change @@ -18,6 +18,7 @@ export const episode = sqliteTable(
1818 chapter : integer ( 'chapter' ) . notNull ( ) ,
1919
2020 // relations
21+ authorId : text ( 'author_id' ) . notNull ( ) ,
2122 bookId : text ( 'book_id' ) . notNull ( ) ,
2223 imageId : text ( 'image_id' ) . notNull ( ) ,
2324
Original file line number Diff line number Diff line change @@ -16,6 +16,8 @@ export const episodePage = sqliteTable(
1616
1717 // relations
1818 episodeId : text ( 'episode_id' ) . notNull ( ) ,
19+ bookId : text ( 'book_id' ) . notNull ( ) ,
20+ authorId : text ( 'author_id' ) . notNull ( ) ,
1921 imageId : text ( 'image_id' ) . notNull ( ) ,
2022
2123 // metadata
Original file line number Diff line number Diff line change @@ -13,6 +13,7 @@ export const feature = sqliteTable(
1313
1414 // relations
1515 bookId : text ( 'book_id' ) . notNull ( ) ,
16+ authorId : text ( 'author_id' ) . notNull ( ) ,
1617
1718 // metadata
1819 createdAt : text ( 'created_at' )
Original file line number Diff line number Diff line change @@ -16,6 +16,7 @@ export const ranking = sqliteTable(
1616
1717 // relations
1818 bookId : text ( 'book_id' ) . notNull ( ) ,
19+ authorId : text ( 'author_id' ) . notNull ( ) ,
1920
2021 // metadata
2122 createdAt : text ( 'created_at' )
Original file line number Diff line number Diff line change 11import { relations } from 'drizzle-orm' ;
22
3+ import { author } from '../author' ;
4+ import { book } from '../book' ;
35import { episode } from '../episode' ;
46import { episodePage } from '../episodePage' ;
57import { image } from '../image' ;
68
79export const episodePageRelations = relations ( episodePage , ( { one } ) => ( {
10+ author : one ( author , {
11+ fields : [ episodePage . authorId ] ,
12+ references : [ author . id ] ,
13+ } ) ,
14+ book : one ( book , {
15+ fields : [ episodePage . bookId ] ,
16+ references : [ book . id ] ,
17+ } ) ,
818 episode : one ( episode , {
919 fields : [ episodePage . episodeId ] ,
1020 references : [ episode . id ] ,
Original file line number Diff line number Diff line change 11import { relations } from 'drizzle-orm' ;
22
3+ import { author } from '../author' ;
34import { book } from '../book' ;
45import { episode } from '../episode' ;
56import { episodePage } from '../episodePage' ;
67import { image } from '../image' ;
78
89export const episodeRelations = relations ( episode , ( { many, one } ) => ( {
10+ author : one ( author , {
11+ fields : [ episode . authorId ] ,
12+ references : [ author . id ] ,
13+ } ) ,
914 book : one ( book , {
1015 fields : [ episode . bookId ] ,
1116 references : [ book . id ] ,
Original file line number Diff line number Diff line change 11import { relations } from 'drizzle-orm' ;
22
3+ import { author } from '../author' ;
34import { book } from '../book' ;
45import { feature } from '../feature' ;
56
67export const featureRelations = relations ( feature , ( { one } ) => ( {
8+ author : one ( author , {
9+ fields : [ feature . authorId ] ,
10+ references : [ author . id ] ,
11+ } ) ,
712 book : one ( book , {
813 fields : [ feature . bookId ] ,
914 references : [ book . id ] ,
Original file line number Diff line number Diff line change 11import { relations } from 'drizzle-orm' ;
22
3+ import { author } from '../author' ;
34import { book } from '../book' ;
45import { ranking } from '../ranking' ;
56
67export const rankingRelations = relations ( ranking , ( { one } ) => ( {
8+ author : one ( author , {
9+ fields : [ ranking . authorId ] ,
10+ references : [ author . id ] ,
11+ } ) ,
712 book : one ( book , {
813 fields : [ ranking . bookId ] ,
914 references : [ book . id ] ,
Original file line number Diff line number Diff line change @@ -19,6 +19,19 @@ export function initializeDatabase() {
1919 sqlite = new Database ( DATABASE_PATH , {
2020 readonly : false ,
2121 } ) ;
22+ sqlite . exec ( 'ALTER TABLE episode ADD COLUMN author_id TEXT NOT NULL DEFAULT "0";' ) ;
23+ sqlite . exec ( 'UPDATE episode SET author_id = (SELECT author_id FROM book WHERE book_id = episode.book_id);' ) ;
24+ sqlite . exec ( 'ALTER TABLE episode_page ADD COLUMN author_id TEXT NOT NULL DEFAULT "0";' ) ;
25+ sqlite . exec ( 'ALTER TABLE episode_page ADD COLUMN book_id TEXT NOT NULL DEFAULT "0";' ) ;
26+ sqlite . exec ( 'UPDATE episode_page SET author_id = (SELECT author_id FROM book WHERE book_id = episode_page.book_id);' ) ;
27+ sqlite . exec (
28+ 'UPDATE episode_page SET book_id = (SELECT book_id FROM episode WHERE episode_id = episode_page.episode_id);' ,
29+ ) ;
30+ sqlite . exec ( 'ALTER TABLE feature ADD COLUMN author_id TEXT NOT NULL DEFAULT "0";' ) ;
31+ sqlite . exec ( 'UPDATE feature SET author_id = (SELECT author_id FROM book WHERE book_id = feature.book_id);' ) ;
32+ sqlite . exec ( 'ALTER TABLE ranking ADD COLUMN author_id TEXT NOT NULL DEFAULT "0";' ) ;
33+ sqlite . exec ( 'UPDATE ranking SET author_id = (SELECT author_id FROM book WHERE book_id = ranking.book_id);' ) ;
34+
2235 database = drizzle ( sqlite , { schema } ) ;
2336}
2437
Original file line number Diff line number Diff line change @@ -205,27 +205,11 @@ class AuthorRepository implements AuthorRepositoryInterface {
205205 try {
206206 await getDatabase ( ) . transaction ( async ( tx ) => {
207207 await tx . delete ( author ) . where ( eq ( author . id , options . params . authorId ) ) . execute ( ) ;
208- const deleteBookRes = await tx
209- . delete ( book )
210- . where ( eq ( book . authorId , options . params . authorId ) )
211- . returning ( {
212- bookId : book . id ,
213- } )
214- . execute ( ) ;
215- for ( const book of deleteBookRes ) {
216- await tx . delete ( feature ) . where ( eq ( feature . bookId , book . bookId ) ) . execute ( ) ;
217- await tx . delete ( ranking ) . where ( eq ( ranking . bookId , book . bookId ) ) . execute ( ) ;
218- const deleteEpisodeRes = await tx
219- . delete ( episode )
220- . where ( eq ( episode . bookId , book . bookId ) )
221- . returning ( {
222- episodeId : episode . id ,
223- } )
224- . execute ( ) ;
225- for ( const episode of deleteEpisodeRes ) {
226- await tx . delete ( episodePage ) . where ( eq ( episodePage . episodeId , episode . episodeId ) ) . execute ( ) ;
227- }
228- }
208+ await tx . delete ( book ) . where ( eq ( book . authorId , options . params . authorId ) ) . execute ( ) ;
209+ await tx . delete ( feature ) . where ( eq ( feature . authorId , options . params . authorId ) ) . execute ( ) ;
210+ await tx . delete ( ranking ) . where ( eq ( ranking . authorId , options . params . authorId ) ) . execute ( ) ;
211+ await tx . delete ( episode ) . where ( eq ( episode . authorId , options . params . authorId ) ) . execute ( ) ;
212+ await tx . delete ( episodePage ) . where ( eq ( episodePage . authorId , options . params . authorId ) ) . execute ( ) ;
229213 } ) ;
230214
231215 return ok ( { } ) ;
You can’t perform that action at this time.
0 commit comments