update.sql 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  1. create table author
  2. (
  3. id int auto_increment primary key,
  4. name varchar(255) not null,
  5. author_id varchar(100) not null,
  6. create_time timestamp default CURRENT_TIMESTAMP null,
  7. update_time timestamp default CURRENT_TIMESTAMP null on update CURRENT_TIMESTAMP,
  8. constraint author_id_unique unique (author_id)
  9. );
  10. create table book
  11. (
  12. id int auto_increment primary key,
  13. book_name varchar(255) not null,
  14. book_id varchar(100) not null,
  15. book_md5 varchar(32) not null,
  16. language varchar(50) null comment '语言',
  17. date date null comment '创建时间',
  18. creatorFileAs varchar(255) null comment '电子书创建人',
  19. UUID varchar(36) null comment '电子书唯一编号',
  20. ISBN varchar(20) null comment '电子书出版编号',
  21. author_id varchar(100) not null comment '作者id',
  22. category_id varchar(255) null comment '书籍类别编号',
  23. Introduction text null comment '简介',
  24. create_time timestamp default CURRENT_TIMESTAMP null,
  25. update_time timestamp default CURRENT_TIMESTAMP null on update CURRENT_TIMESTAMP,
  26. constraint book_id_unique unique (book_id)
  27. ) comment '书籍信息';
  28. create table category
  29. (
  30. id int auto_increment primary key,
  31. name varchar(255) not null,
  32. create_time timestamp default CURRENT_TIMESTAMP null,
  33. update_time timestamp default CURRENT_TIMESTAMP null on update CURRENT_TIMESTAMP
  34. );
  35. create table chapter
  36. (
  37. id int auto_increment primary key,
  38. name varchar(255) not null,
  39. book_id varchar(100) not null,
  40. author_id varchar(100) not null,
  41. content longtext null,
  42. level int null,
  43. order_index int null,
  44. order_id varchar(255) null,
  45. old_path varchar(255) null,
  46. path varchar(255) null,
  47. create_time timestamp default CURRENT_TIMESTAMP null,
  48. update_time timestamp default CURRENT_TIMESTAMP null on update CURRENT_TIMESTAMP,
  49. constraint fk_chapter_author foreign key (author_id) references author (author_id) on delete cascade,
  50. constraint fk_chapter_book foreign key (book_id) references book (book_id) on delete cascade
  51. );
  52. create table files
  53. (
  54. id int auto_increment primary key,
  55. file_id varchar(100) not null,
  56. md5 varchar(32) not null,
  57. mimetype varchar(255) not null,
  58. size int not null,
  59. name varchar(255) null,
  60. path varchar(255) null,
  61. create_time timestamp default CURRENT_TIMESTAMP null,
  62. update_time timestamp default CURRENT_TIMESTAMP null on update CURRENT_TIMESTAMP,
  63. constraint file_id_unique unique (file_id)
  64. );
  65. create table book_link_file
  66. (
  67. id int auto_increment primary key,
  68. file_id varchar(100) not null,
  69. book_id varchar(100) not null,
  70. author_id varchar(100) not null,
  71. create_time timestamp default CURRENT_TIMESTAMP null,
  72. update_time timestamp default CURRENT_TIMESTAMP null on update CURRENT_TIMESTAMP,
  73. constraint fk_book_file foreign key (file_id) references files (file_id) on delete cascade,
  74. constraint fk_link_author foreign key (author_id) references author (author_id) on delete cascade,
  75. constraint fk_link_book foreign key (book_id) references book (book_id) on delete cascade
  76. );
  77. create table style
  78. (
  79. id int auto_increment primary key,
  80. name varchar(255) not null,
  81. style_id varchar(100) not null,
  82. create_time timestamp default CURRENT_TIMESTAMP null,
  83. update_time timestamp default CURRENT_TIMESTAMP null on update CURRENT_TIMESTAMP,
  84. constraint style_id_unique unique (style_id)
  85. );
  86. create table style_link_book
  87. (
  88. id int auto_increment primary key,
  89. style_id varchar(100) not null,
  90. book_id varchar(100) not null,
  91. create_time timestamp default CURRENT_TIMESTAMP null,
  92. update_time timestamp default CURRENT_TIMESTAMP null on update CURRENT_TIMESTAMP,
  93. constraint style_book_unique unique (style_id, book_id),
  94. constraint fk_book foreign key (book_id) references book (book_id) on delete cascade,
  95. constraint fk_style foreign key (style_id) references style (style_id) on delete cascade
  96. );
  97. ALTER TABLE epub_manage.chapter ADD level INT NULL;
  98. ALTER TABLE epub_manage.chapter ADD order_index INT NULL;
  99. ALTER TABLE epub_manage.chapter ADD order_id VARCHAR(255) NULL;
  100. ALTER TABLE epub_manage.chapter ADD old_path VARCHAR(255) NULL;
  101. ALTER TABLE epub_manage.chapter ADD path VARCHAR(255) NULL;
  102. alter table chapter
  103. modify content varchar(255) null;
  104. CREATE INDEX idx_files_source_id ON files (source_id);
  105. SELECT f.*, chapter.*
  106. FROM files f
  107. JOIN epub_manage.book_link_file blf ON f.file_id = blf.file_id
  108. JOIN epub_manage.chapter chapter ON chapter.order_id = blf.file_id
  109. WHERE blf.book_id = '1a7c3ccc61a0c00998d588971ee4e567'
  110. AND f.id > (
  111. SELECT f2.id
  112. FROM files f2
  113. JOIN epub_manage.book_link_file blf2 ON f2.file_id = blf2.file_id
  114. WHERE f2.file_id = '65403824ba1ebed1576f950d4fb495c0'
  115. AND blf2.book_id = '1a7c3ccc61a0c00998d588971ee4e567'
  116. LIMIT 1
  117. )
  118. ORDER BY f.id ASC
  119. LIMIT 1;
  120. select * from files f JOIN epub_manage.book_link_file blf ON f.file_id = blf.file_id and blf.book_id = '1a7c3ccc61a0c00998d588971ee4e567' where f.file_id = '65403824ba1ebed1576f950d4fb495c0' ORDER BY f.id ASC
  121. LIMIT 2;
  122. SELECT *
  123. FROM files f
  124. JOIN epub_manage.book_link_file blf ON f.file_id = blf.file_id
  125. WHERE blf.book_id = '1a7c3ccc61a0c00998d588971ee4e567' -- 需要根据实际情况填写
  126. AND f.id > (
  127. SELECT MAX(f2.id)
  128. FROM files f2
  129. JOIN epub_manage.book_link_file blf2 ON f2.file_id = blf2.file_id
  130. WHERE f2.file_id = '65403824ba1ebed1576f950d4fb495c0'
  131. )
  132. ORDER BY f.id ASC
  133. LIMIT 1;
  134. SELECT f.*
  135. FROM files f
  136. JOIN epub_manage.book_link_file blf ON f.file_id = blf.file_id
  137. WHERE blf.book_id = '1a7c3ccc61a0c00998d588971ee4e567'
  138. AND f.id > (
  139. SELECT f2.id
  140. FROM files f2
  141. WHERE f2.file_id = '65403824ba1ebed1576f950d4fb495c0'
  142. ORDER BY f2.id DESC
  143. LIMIT 1
  144. )
  145. ORDER BY f.id ASC
  146. LIMIT 1;