例子一

  1. # 创建用户表
  2. CREATE TABLE `user` (
  3. `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
  4. `created_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
  5. `updated_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
  6. `password` varchar(20) NOT NULL,
  7. `username` varchar(100) NOT NULL,
  8. PRIMARY KEY (`id`),
  9. UNIQUE KEY `user_username_uindex` (`username`)
  10. ) ENGINE=InnoDB AUTO_INCREMENT=15 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci
  1. # i18n 语言表
  2. CREATE TABLE `i18n_config` (
  3. `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
  4. `type` varchar(10) NOT NULL,
  5. `key_name` text NOT NULL,
  6. `value` text NOT NULL,
  7. `comment` varchar(50) DEFAULT NULL,
  8. `scene` varchar(512) DEFAULT NULL,
  9. `deleted_at` datetime DEFAULT NULL,
  10. `updated_by` varchar(128) DEFAULT NULL,
  11. `created_by` varchar(128) DEFAULT NULL,
  12. `is_delete` tinyint(1) DEFAULT '0',
  13. `created_at` datetime DEFAULT CURRENT_TIMESTAMP,
  14. `updated_at` datetime DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
  15. `unique_md5` varchar(16) DEFAULT NULL COMMENT '唯一索引',
  16. PRIMARY KEY (`id`),
  17. UNIQUE KEY `unique_md5_index` (`unique_md5`)
  18. ) ENGINE=InnoDB AUTO_INCREMENT=412544 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;
  19. ALTER TABLE i18n_config ADD unique_md5 varchar(16) DEFAULT NULL COMMENT '唯一索引';
  20. create unique index unique_md5_index on i18n_config (unique_md5);
  21. alter table i18n_config add status tinyint DEFAULT NULL COMMENT "新增待上架(status = 1)变更待同步 (status = 2)上架(status = 3)待下架(status = 4) 下架(status = 5)"
  22. alter table i18n_config add scene varchar(512) DEFAULT NULL COMMENT "场景"
  23. alter table i18n_config add `operator` tinyint(4) DEFAULT NULL COMMENT '创建(operator = 1)修改(operator = 2)删除(operator = 3)',
  1. # i18n 描述表
  2. CREATE TABLE `i18n_comment` (
  3. `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
  4. `cn_value` text NOT NULL,
  5. `comment` varchar(50) DEFAULT NULL,
  6. `en_unique_md5` varchar(16) DEFAULT NULL COMMENT '唯一索引',
  7. `created_at` datetime DEFAULT CURRENT_TIMESTAMP,
  8. `updated_at` datetime DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
  9. `deleted_at` datetime DEFAULT NULL,
  10. `created_by` varchar(128) DEFAULT NULL,
  11. `updated_by` varchar(128) DEFAULT NULL,
  12. `is_delete` tinyint(1) DEFAULT '0',
  13. PRIMARY KEY (`id`)
  14. ) ENGINE=InnoDB AUTO_INCREMENT=10000 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;
  1. # 应用类型 与 语言未上架数据表 关联表
  2. CREATE TABLE `i18n_classify_mapping_status_data` (
  3. `classify_id` bigint(20) unsigned NOT NULL,
  4. `en_unique_md5` varchar(16) DEFAULT NULL COMMENT '唯一索引',
  5. `created_at` datetime DEFAULT CURRENT_TIMESTAMP,
  6. `updated_at` datetime DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
  7. `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
  8. PRIMARY KEY (`id`),
  9. UNIQUE KEY `index_name` (`classify_id`,`en_unique_md5`)
  10. ) ENGINE=InnoDB AUTO_INCREMENT=376543 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci
  11. # i18n 语言未上架数据表
  12. CREATE TABLE `i18n_config_status_data` (
  13. `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
  14. `type` varchar(10) NOT NULL,
  15. `key_name` text NOT NULL,
  16. `value` text NOT NULL,
  17. `comment` varchar(50) DEFAULT NULL,
  18. `deleted_at` datetime DEFAULT NULL,
  19. `updated_by` varchar(128) DEFAULT NULL,
  20. `created_by` varchar(128) DEFAULT NULL,
  21. `scene` varchar(512) DEFAULT NULL,
  22. `is_delete` tinyint(1) DEFAULT '0',
  23. `created_at` datetime DEFAULT CURRENT_TIMESTAMP,
  24. `updated_at` datetime DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
  25. `unique_md5` varchar(16) DEFAULT NULL COMMENT '唯一索引',
  26. `status` tinyint(4) DEFAULT NULL COMMENT '新增待上架(status = 1)变更待同步 (status = 2)上架(status = 3)待下架(status = 4) 下架(status = 5)',
  27. `operator` tinyint(4) DEFAULT NULL COMMENT '创建(operator = 1)修改(operator = 2)删除(operator = 3)',
  28. PRIMARY KEY (`id`),
  29. UNIQUE KEY `unique_md5_index` (`unique_md5`)
  30. ) ENGINE=InnoDB AUTO_INCREMENT=10000 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci'
  1. # i18n 分类表
  2. CREATE TABLE `i18n_classify` (
  3. `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
  4. `name` varchar(50) NOT NULL,
  5. `updated_by` varchar(128) DEFAULT NULL,
  6. `created_by` varchar(128) DEFAULT NULL,
  7. `is_delete` tinyint(1) DEFAULT '0',
  8. `created_at` datetime DEFAULT CURRENT_TIMESTAMP,
  9. `updated_at` datetime DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
  10. PRIMARY KEY (`id`),
  11. UNIQUE KEY `i18n_classify_uname` (`name`)
  12. ) ENGINE=InnoDB AUTO_INCREMENT=10000 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;
  13. INSERT INTO i18n_classify (name) values ('PC');
  14. INSERT INTO i18n_classify (name) values ('H5');
  15. INSERT INTO i18n_classify (name) values ('Android');
  16. INSERT INTO i18n_classify (name) values ('IOS');
  17. INSERT INTO i18n_classify (name) values ('ContentMarketing');
  1. # i18n 分类和语言表mapping表
  2. CREATE TABLE `i18n_classify_mapping` (
  3. `classify_id` bigint(20) unsigned NOT NULL,
  4. `i18n_id` bigint(20) unsigned NOT NULL
  5. ) ENGINE=InnoDB CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;
  6. ALTER TABLE i18n_classify_mapping ADD `updated_at` datetime DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP;
  7. ALTER TABLE i18n_classify_mapping ADD `created_at` datetime DEFAULT CURRENT_TIMESTAMP;
  8. ALTER TABLE i18n_classify_mapping ADD `id` bigint(20) unsigned NOT NULL;
  9. ALTER TABLE i18n_classify_mapping ADD PRIMARY KEY (id);
  10. ALTER TABLE i18n_classify_mapping MODIFY id bigint(20) unsigned NOT NULL AUTO_INCREMENT;
  11. ALTER TABLE i18n_classify_mapping ADD UNIQUE index_name(classify_id, i18n_id);
  12. CREATE TABLE `i18n_classify_mapping` (
  13. `classify_id` bigint(20) unsigned NOT NULL,
  14. `i18n_id` bigint(20) unsigned NOT NULL,
  15. `created_at` datetime DEFAULT CURRENT_TIMESTAMP,
  16. `updated_at` datetime DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
  17. `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
  18. PRIMARY KEY (`id`),
  19. UNIQUE KEY `index_name` (`classify_id`,`i18n_id`)
  20. ) ENGINE=InnoDB AUTO_INCREMENT=37 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;
  1. CREATE TABLE `data_options` (
  2. `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
  3. `parent_id` bigint(20) DEFAULT NULL,
  4. `type` varchar(128) NOT NULL COMMENT '一级分类',
  5. `value` varchar(512) NOT NULL,
  6. `class_type` varchar(128) DEFAULT NULL COMMENT '二级分类',
  7. PRIMARY KEY (`id`)
  8. ) ENGINE=InnoDB AUTO_INCREMENT=10000 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci
  9. alter table data_options auto_increment=10000;
  10. insert into data_options (type, value, parent_id) values ('version', '1.0.0', 10000);
  11. insert into data_options (type, value, parent_id) values ('version', '1.0.0', 10001);
  12. insert into data_options (type, value, parent_id) values ('version', '1.0.0', 10002);
  13. insert into data_options (type, value, parent_id) values ('version', '1.0.0', 10003);
  14. insert into data_options (type, value, parent_id) values ('version', '1.0.0', 10004);
  1. alter table yida_pages MODIFY page_data LONGTEXT not null

image.png

  1. // insert into user (id, username, password, created_at) values (10000, 'ljy', '9abbc042f6b66cb88411', '2022-05-02 13:28:00');
  2. const random = require('string-random');
  3. const password = random(16, { specials: true });
  4. const crypto = require('crypto');
  5. const salt = 'xxx_config_center';
  6. const getSaltPassword = password => {
  7. return crypto.createHash('md5').update(password + salt).digest('hex')
  8. .substr(0, 20);
  9. }
  10. console.log(password);
  11. console.log(getSaltPassword(password));
  12. // 'XhY.yq8^(E:Pu{gY'
  13. // '9abbc042f6b66cb88411'

sql 查询

  1. let str = '';
  2. let copyStr = '';
  3. const params = [ type ];
  4. if (keyName) {
  5. str = 'and A.key_name = ?';
  6. params.push(keyName);
  7. }
  8. params.push(type);
  9. if (keyName) {
  10. copyStr = 'and key_name = ?';
  11. params.push(keyName);
  12. }
  13. const fields = [ 'id', 'type', 'key_name', 'value', 'comment', 'deleted_at', 'updated_by', 'created_by', 'is_delete', 'created_at', 'updated_at', 'unique_md5', 'status', 'en_unique_md5', 'scene', 'operator' ];
  14. let fieldStr = '';
  15. let fieldStrCopy = '';
  16. fields.forEach((key, index) => {
  17. if (index === fields.length - 1) {
  18. fieldStr += `IFNULL(B.${key}, A.${key}) as ${key}`;
  19. fieldStrCopy += `${key}`;
  20. return;
  21. }
  22. fieldStr += `IFNULL(B.${key}, A.${key}) as ${key}, `;
  23. fieldStrCopy += `${key}, `;
  24. });
  25. const sql = `select ${fieldStr} from i18n_config A left join i18n_config_status_data B ON A.unique_md5 = B.unique_md5 where A.type = ? ${str}
  26. UNION select ${fieldStrCopy} from i18n_config_status_data B where status = 1 and type = ? ${copyStr}
  27. `;