schema.sql 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236
  1. # Tables
  2. CREATE TABLE fave_blog_cats (
  3. id int(11) NOT NULL AUTO_INCREMENT COMMENT 'AI',
  4. user int(11) NOT NULL COMMENT 'User id',
  5. name varchar(255) NOT NULL COMMENT 'Category name',
  6. alias varchar(255) NOT NULL COMMENT 'Category alias',
  7. lft int(11) NOT NULL COMMENT 'For nested set model',
  8. rgt int(11) NOT NULL COMMENT 'For nested set model',
  9. PRIMARY KEY (id)
  10. ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
  11. CREATE TABLE fave_blog_cat_post_rel (
  12. post_id int(11) NOT NULL COMMENT 'Post id',
  13. category_id int(11) NOT NULL COMMENT 'Category id'
  14. ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
  15. CREATE TABLE fave_blog_posts (
  16. id int(11) NOT NULL AUTO_INCREMENT COMMENT 'AI',
  17. user int(11) NOT NULL COMMENT 'User id',
  18. name varchar(255) NOT NULL COMMENT 'Post name',
  19. alias varchar(255) NOT NULL COMMENT 'Post alias',
  20. category int(11) NOT NULL,
  21. briefly text NOT NULL COMMENT 'Post brief content',
  22. content text NOT NULL COMMENT 'Post content',
  23. datetime datetime NOT NULL COMMENT 'Creation date/time',
  24. active int(1) NOT NULL COMMENT 'Is active post or not',
  25. PRIMARY KEY (id)
  26. ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
  27. CREATE TABLE fave_notify_mail (
  28. id int(11) NOT NULL AUTO_INCREMENT COMMENT 'AI',
  29. email varchar(255) NOT NULL COMMENT 'Email address',
  30. subject varchar(800) NOT NULL COMMENT 'Email subject',
  31. message text NOT NULL COMMENT 'Email body',
  32. error text NOT NULL COMMENT 'Send error message',
  33. datetime datetime NOT NULL COMMENT 'Creation date/time',
  34. status int(1) NOT NULL COMMENT 'Sending status',
  35. PRIMARY KEY (id)
  36. ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
  37. CREATE TABLE fave_pages (
  38. id int(11) NOT NULL AUTO_INCREMENT COMMENT 'AI',
  39. user int(11) NOT NULL COMMENT 'User id',
  40. template varchar(255) NOT NULL DEFAULT 'page' COMMENT 'Template',
  41. name varchar(255) NOT NULL COMMENT 'Page name',
  42. alias varchar(255) NOT NULL COMMENT 'Page url part',
  43. content text NOT NULL COMMENT 'Page content',
  44. meta_title varchar(255) NOT NULL DEFAULT '' COMMENT 'Page meta title',
  45. meta_keywords varchar(255) NOT NULL DEFAULT '' COMMENT 'Page meta keywords',
  46. meta_description varchar(510) NOT NULL DEFAULT '' COMMENT 'Page meta description',
  47. datetime datetime NOT NULL COMMENT 'Creation date/time',
  48. active int(1) NOT NULL COMMENT 'Is active page or not',
  49. PRIMARY KEY (id)
  50. ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
  51. CREATE TABLE fave_settings (
  52. name varchar(255) NOT NULL COMMENT 'Setting name',
  53. value text NOT NULL COMMENT 'Setting value'
  54. ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
  55. CREATE TABLE fave_shop_cat_product_rel (
  56. product_id int(11) NOT NULL COMMENT 'Product id',
  57. category_id int(11) NOT NULL COMMENT 'Category id'
  58. ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
  59. CREATE TABLE fave_shop_cats (
  60. id int(11) NOT NULL AUTO_INCREMENT COMMENT 'AI',
  61. user int(11) NOT NULL COMMENT 'User id',
  62. name varchar(255) NOT NULL COMMENT 'Category name',
  63. alias varchar(255) NOT NULL COMMENT 'Category alias',
  64. lft int(11) NOT NULL COMMENT 'For nested set model',
  65. rgt int(11) NOT NULL COMMENT 'For nested set model',
  66. PRIMARY KEY (id)
  67. ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
  68. CREATE TABLE fave_shop_currencies (
  69. id int(11) NOT NULL AUTO_INCREMENT COMMENT 'AI',
  70. name varchar(255) NOT NULL COMMENT 'Currency name',
  71. coefficient float(8,4) NOT NULL DEFAULT '1.0000' COMMENT 'Currency coefficient',
  72. code varchar(10) NOT NULL COMMENT 'Currency code',
  73. symbol varchar(5) NOT NULL COMMENT 'Currency symbol',
  74. PRIMARY KEY (id)
  75. ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
  76. CREATE TABLE fave_shop_filter_product_values (
  77. product_id int(11) NOT NULL COMMENT 'Product id',
  78. filter_value_id int(11) NOT NULL COMMENT 'Filter value id'
  79. ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
  80. CREATE TABLE fave_shop_filters (
  81. id int(11) NOT NULL AUTO_INCREMENT COMMENT 'AI',
  82. name varchar(255) NOT NULL COMMENT 'Filter name in CP',
  83. filter varchar(255) NOT NULL COMMENT 'Filter name in site',
  84. PRIMARY KEY (id)
  85. ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
  86. CREATE TABLE fave_shop_filters_values (
  87. id int(11) NOT NULL AUTO_INCREMENT COMMENT 'AI',
  88. filter_id int(11) NOT NULL COMMENT 'Filter id',
  89. name varchar(255) NOT NULL COMMENT 'Value name',
  90. PRIMARY KEY (id)
  91. ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
  92. CREATE TABLE fave_shop_order_products (
  93. id int(11) NOT NULL AUTO_INCREMENT COMMENT 'AI',
  94. order_id int(11) NOT NULL COMMENT 'Order ID',
  95. product_id int(11) NOT NULL COMMENT 'Product ID',
  96. price float(8,2) NOT NULL COMMENT 'Product price',
  97. quantity int(11) NOT NULL COMMENT 'Quantity',
  98. PRIMARY KEY (id)
  99. ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
  100. CREATE TABLE fave_shop_orders (
  101. id int(11) NOT NULL AUTO_INCREMENT COMMENT 'AI',
  102. create_datetime datetime NOT NULL COMMENT 'Create date/time',
  103. update_datetime datetime NOT NULL COMMENT 'Update date/time',
  104. currency_id int(11) NOT NULL COMMENT 'Currency ID',
  105. currency_name varchar(255) NOT NULL COMMENT 'Currency name',
  106. currency_coefficient float(8,4) NOT NULL DEFAULT '1.0000' COMMENT 'Currency coefficient',
  107. currency_code varchar(10) NOT NULL COMMENT 'Currency code',
  108. currency_symbol varchar(5) NOT NULL COMMENT 'Currency symbol',
  109. client_last_name varchar(64) NOT NULL COMMENT 'Client last name',
  110. client_first_name varchar(64) NOT NULL COMMENT 'Client first name',
  111. client_middle_name varchar(64) NOT NULL DEFAULT '' COMMENT 'Client middle name',
  112. client_phone varchar(20) NOT NULL DEFAULT '' COMMENT 'Client phone',
  113. client_email varchar(64) NOT NULL COMMENT 'Client email',
  114. client_delivery_comment text NOT NULL COMMENT 'Client delivery comment',
  115. client_order_comment text NOT NULL COMMENT 'Client order comment',
  116. status int(1) NOT NULL COMMENT 'new/confirmed/inprogress/canceled/completed',
  117. PRIMARY KEY (id)
  118. ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
  119. CREATE TABLE fave_shop_product_images (
  120. id int(11) NOT NULL AUTO_INCREMENT,
  121. product_id int(11) NOT NULL,
  122. filename varchar(255) NOT NULL,
  123. ord int(11) NOT NULL DEFAULT '0',
  124. PRIMARY KEY (id)
  125. ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
  126. CREATE TABLE fave_shop_products (
  127. id int(11) NOT NULL AUTO_INCREMENT COMMENT 'AI',
  128. parent_id int(11) DEFAULT NULL,
  129. user int(11) NOT NULL COMMENT 'User id',
  130. currency int(11) NOT NULL COMMENT 'Currency id',
  131. price float(8,2) NOT NULL COMMENT 'Product price',
  132. price_old float(8,2) NOT NULL DEFAULT '0.00',
  133. price_promo float(8,2) NOT NULL DEFAULT '0.00',
  134. gname varchar(255) NOT NULL,
  135. name varchar(255) NOT NULL COMMENT 'Product name',
  136. alias varchar(255) NOT NULL COMMENT 'Product alias',
  137. vendor varchar(255) NOT NULL,
  138. quantity int(11) NOT NULL,
  139. category int(11) NOT NULL,
  140. briefly text NOT NULL COMMENT 'Product brief content',
  141. content text NOT NULL COMMENT 'Product content',
  142. datetime datetime NOT NULL COMMENT 'Creation date/time',
  143. active int(1) NOT NULL COMMENT 'Is active product or not',
  144. custom1 varchar(2048) NOT NULL DEFAULT '',
  145. custom2 varchar(2048) NOT NULL DEFAULT '',
  146. PRIMARY KEY (id)
  147. ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
  148. CREATE TABLE fave_users (
  149. id int(11) NOT NULL AUTO_INCREMENT COMMENT 'AI',
  150. first_name varchar(64) NOT NULL DEFAULT '' COMMENT 'User first name',
  151. last_name varchar(64) NOT NULL DEFAULT '' COMMENT 'User last name',
  152. email varchar(64) NOT NULL COMMENT 'User email',
  153. password varchar(32) NOT NULL COMMENT 'User password (MD5)',
  154. admin int(1) NOT NULL COMMENT 'Is admin user or not',
  155. active int(1) NOT NULL COMMENT 'Is active user or not',
  156. PRIMARY KEY (id)
  157. ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
  158. # Indexes
  159. ALTER TABLE fave_blog_cat_post_rel ADD UNIQUE KEY post_category (post_id,category_id) USING BTREE;
  160. ALTER TABLE fave_blog_cat_post_rel ADD KEY FK_blog_cat_post_rel_post_id (post_id);
  161. ALTER TABLE fave_blog_cat_post_rel ADD KEY FK_blog_cat_post_rel_category_id (category_id);
  162. ALTER TABLE fave_blog_cats ADD UNIQUE KEY alias (alias);
  163. ALTER TABLE fave_blog_cats ADD KEY lft (lft), ADD KEY rgt (rgt);
  164. ALTER TABLE fave_blog_cats ADD KEY FK_blog_cats_user (user);
  165. ALTER TABLE fave_blog_posts ADD UNIQUE KEY alias (alias);
  166. ALTER TABLE fave_blog_posts ADD KEY FK_blog_posts_user (user);
  167. ALTER TABLE fave_blog_posts ADD KEY FK_blog_posts_category (category);
  168. ALTER TABLE fave_notify_mail ADD KEY status (status);
  169. ALTER TABLE fave_pages ADD UNIQUE KEY alias (alias);
  170. ALTER TABLE fave_pages ADD KEY alias_active (alias,active) USING BTREE;
  171. ALTER TABLE fave_pages ADD KEY FK_pages_user (user);
  172. ALTER TABLE fave_settings ADD UNIQUE KEY name (name);
  173. ALTER TABLE fave_shop_cat_product_rel ADD UNIQUE KEY product_category (product_id,category_id) USING BTREE;
  174. ALTER TABLE fave_shop_cat_product_rel ADD KEY FK_shop_cat_product_rel_product_id (product_id);
  175. ALTER TABLE fave_shop_cat_product_rel ADD KEY FK_shop_cat_product_rel_category_id (category_id);
  176. ALTER TABLE fave_shop_cats ADD UNIQUE KEY alias (alias);
  177. ALTER TABLE fave_shop_cats ADD KEY lft (lft), ADD KEY rgt (rgt);
  178. ALTER TABLE fave_shop_cats ADD KEY FK_shop_cats_user (user);
  179. ALTER TABLE fave_shop_filter_product_values ADD UNIQUE KEY product_filter_value (product_id,filter_value_id) USING BTREE;
  180. ALTER TABLE fave_shop_filter_product_values ADD KEY FK_shop_filter_product_values_product_id (product_id);
  181. ALTER TABLE fave_shop_filter_product_values ADD KEY FK_shop_filter_product_values_filter_value_id (filter_value_id);
  182. ALTER TABLE fave_shop_filters ADD KEY name (name);
  183. ALTER TABLE fave_shop_filters_values ADD KEY FK_shop_filters_values_filter_id (filter_id);
  184. ALTER TABLE fave_shop_filters_values ADD KEY name (name);
  185. ALTER TABLE fave_shop_orders ADD KEY FK_shop_orders_currency_id (currency_id);
  186. ALTER TABLE fave_shop_order_products ADD UNIQUE KEY order_product (order_id,product_id) USING BTREE;
  187. ALTER TABLE fave_shop_order_products ADD KEY FK_shop_order_products_order_id (order_id);
  188. ALTER TABLE fave_shop_order_products ADD KEY FK_shop_order_products_product_id (product_id);
  189. ALTER TABLE fave_shop_product_images ADD UNIQUE KEY product_filename (product_id,filename) USING BTREE;
  190. ALTER TABLE fave_shop_product_images ADD KEY FK_shop_product_images_product_id (product_id);
  191. ALTER TABLE fave_shop_products ADD UNIQUE KEY alias (alias);
  192. ALTER TABLE fave_shop_products ADD KEY FK_shop_products_user (user);
  193. ALTER TABLE fave_shop_products ADD KEY FK_shop_products_currency (currency);
  194. ALTER TABLE fave_shop_products ADD KEY FK_shop_products_category (category);
  195. ALTER TABLE fave_shop_products ADD KEY FK_shop_products_parent_id (parent_id);
  196. ALTER TABLE fave_shop_products ADD KEY name (name);
  197. ALTER TABLE fave_users ADD UNIQUE KEY email (email);
  198. # References
  199. ALTER TABLE fave_blog_cat_post_rel ADD CONSTRAINT FK_blog_cat_post_rel_post_id FOREIGN KEY (post_id) REFERENCES fave_blog_posts (id) ON DELETE RESTRICT;
  200. ALTER TABLE fave_blog_cat_post_rel ADD CONSTRAINT FK_blog_cat_post_rel_category_id FOREIGN KEY (category_id) REFERENCES fave_blog_cats (id) ON DELETE RESTRICT;
  201. ALTER TABLE fave_blog_cats ADD CONSTRAINT FK_blog_cats_user FOREIGN KEY (user) REFERENCES fave_users (id) ON DELETE RESTRICT;
  202. ALTER TABLE fave_blog_posts ADD CONSTRAINT FK_blog_posts_user FOREIGN KEY (user) REFERENCES fave_users (id) ON DELETE RESTRICT;
  203. ALTER TABLE fave_blog_posts ADD CONSTRAINT FK_blog_posts_category FOREIGN KEY (category) REFERENCES fave_blog_cats (id) ON DELETE RESTRICT;
  204. ALTER TABLE fave_pages ADD CONSTRAINT FK_pages_user FOREIGN KEY (user) REFERENCES fave_users (id) ON DELETE RESTRICT;
  205. ALTER TABLE fave_shop_cat_product_rel ADD CONSTRAINT FK_shop_cat_product_rel_product_id FOREIGN KEY (product_id) REFERENCES fave_shop_products (id) ON DELETE RESTRICT;
  206. ALTER TABLE fave_shop_cat_product_rel ADD CONSTRAINT FK_shop_cat_product_rel_category_id FOREIGN KEY (category_id) REFERENCES fave_shop_cats (id) ON DELETE RESTRICT;
  207. ALTER TABLE fave_shop_cats ADD CONSTRAINT FK_shop_cats_user FOREIGN KEY (user) REFERENCES fave_users (id) ON DELETE RESTRICT;
  208. ALTER TABLE fave_shop_filter_product_values ADD CONSTRAINT FK_shop_filter_product_values_product_id FOREIGN KEY (product_id) REFERENCES fave_shop_products (id) ON DELETE RESTRICT;
  209. ALTER TABLE fave_shop_filter_product_values ADD CONSTRAINT FK_shop_filter_product_values_filter_value_id FOREIGN KEY (filter_value_id) REFERENCES fave_shop_filters_values (id) ON DELETE RESTRICT;
  210. ALTER TABLE fave_shop_filters_values ADD CONSTRAINT FK_shop_filters_values_filter_id FOREIGN KEY (filter_id) REFERENCES fave_shop_filters (id) ON DELETE RESTRICT;
  211. ALTER TABLE fave_shop_orders ADD CONSTRAINT FK_shop_orders_currency_id FOREIGN KEY (currency_id) REFERENCES fave_shop_currencies (id) ON DELETE RESTRICT;
  212. ALTER TABLE fave_shop_order_products ADD CONSTRAINT FK_shop_order_products_order_id FOREIGN KEY (order_id) REFERENCES fave_shop_orders (id) ON DELETE RESTRICT;
  213. ALTER TABLE fave_shop_order_products ADD CONSTRAINT FK_shop_order_products_product_id FOREIGN KEY (product_id) REFERENCES fave_shop_products (id) ON DELETE RESTRICT;
  214. ALTER TABLE fave_shop_product_images ADD CONSTRAINT FK_shop_product_images_product_id FOREIGN KEY (product_id) REFERENCES fave_shop_products (id) ON DELETE RESTRICT;
  215. ALTER TABLE fave_shop_products ADD CONSTRAINT FK_shop_products_user FOREIGN KEY (user) REFERENCES fave_users (id) ON DELETE RESTRICT;
  216. ALTER TABLE fave_shop_products ADD CONSTRAINT FK_shop_products_currency FOREIGN KEY (currency) REFERENCES fave_shop_currencies (id) ON DELETE RESTRICT;
  217. ALTER TABLE fave_shop_products ADD CONSTRAINT FK_shop_products_category FOREIGN KEY (category) REFERENCES fave_shop_cats (id) ON DELETE RESTRICT;
  218. ALTER TABLE fave_shop_products ADD CONSTRAINT FK_shop_products_parent_id FOREIGN KEY (parent_id) REFERENCES fave_shop_products (id) ON DELETE RESTRICT;