From 3cf551c2c0beb020f3603c8fa6e9a1ba864b8a46 Mon Sep 17 00:00:00 2001 From: clz Date: Mon, 12 Jun 2023 18:19:36 +0800 Subject: [PATCH] refactor: rm other sql --- internal/infrastructure/sqlite.go | 2 +- scripts/billMigrations.sql | 75 ------------------------------- scripts/migrations.sql | 60 +++++++------------------ scripts/sqliteMigrations.sql | 16 ------- 4 files changed, 16 insertions(+), 137 deletions(-) delete mode 100644 scripts/billMigrations.sql delete mode 100644 scripts/sqliteMigrations.sql diff --git a/internal/infrastructure/sqlite.go b/internal/infrastructure/sqlite.go index 923253d..13b1854 100644 --- a/internal/infrastructure/sqlite.go +++ b/internal/infrastructure/sqlite.go @@ -37,7 +37,7 @@ func ConnectToSqlite() (*gorm.DB, error) { // migrate data if os.Getenv("ENV") != "prod" { go func() { - sql, err := os.ReadFile("scripts/sqliteMigrations.sql") + sql, err := os.ReadFile("scripts/migrations.sql") if err != nil { //panic("failed to read migration sql file: " + err.Error()) log.Fatal("failed to read migration sql file: " + err.Error()) diff --git a/scripts/billMigrations.sql b/scripts/billMigrations.sql deleted file mode 100644 index 49fbb5e..0000000 --- a/scripts/billMigrations.sql +++ /dev/null @@ -1,75 +0,0 @@ -DROP DATABASE IF EXISTS bill; -CREATE DATABASE IF NOT EXISTS bill; -USE bill; - -create table Bills -( - id int auto_increment primary key, - type varchar(15) not null, - date varchar(15) not null, - money varchar(900) null, - cls varchar(900) null, - label varchar(900) null, - options varchar(900) null -); - -INSERT INTO bill.Bills (id, type, date, money, cls, label, options) -VALUES (3341, 'INCOME', '2022-09-01', '8.5', '交通', '打的', ''); -INSERT INTO bill.Bills (id, type, date, money, cls, label, options) -VALUES (3342, 'INCOME', '2022-09-01', '2.0', '交通', '公交', ''); -INSERT INTO bill.Bills (id, type, date, money, cls, label, options) -VALUES (3343, 'INCOME', '2022-09-01', '43.0', '交通', '其他', '巴士 回房县'); -INSERT INTO bill.Bills (id, type, date, money, cls, label, options) -VALUES (3344, 'INCOME', '2022-09-01', '5.0', '餐饮', '饮料', ''); -INSERT INTO bill.Bills (id, type, date, money, cls, label, options) -VALUES (3345, 'INCOME', '2022-09-01', '4.0', '交通', '公交', ''); -INSERT INTO bill.Bills (id, type, date, money, cls, label, options) -VALUES (3346, 'INCOME', '2022-09-04', '168.0', '餐饮', '聚餐', '胖嫂烧烤'); -INSERT INTO bill.Bills (id, type, date, money, cls, label, options) -VALUES (3347, 'INCOME', '2022-09-03', '27.0', '餐饮', '零食', ''); -INSERT INTO bill.Bills (id, type, date, money, cls, label, options) -VALUES (3348, 'INCOME', '2022-09-06', '186.0', '交通', '高铁', '回武汉的高铁票'); -INSERT INTO bill.Bills (id, type, date, money, cls, label, options) -VALUES (3349, 'INCOME', '2022-09-06', '4.0', '餐饮', '饮料', ''); -INSERT INTO bill.Bills (id, type, date, money, cls, label, options) -VALUES (3350, 'INCOME', '2022-09-06', '5.0', '餐饮', '早餐', ''); -INSERT INTO bill.Bills (id, type, date, money, cls, label, options) -VALUES (3351, 'INCOME', '2022-07-04', '17.9', '餐饮', '晚餐', ''); -INSERT INTO bill.Bills (id, type, date, money, cls, label, options) -VALUES (3352, 'INCOME', '2022-07-04', '18.5', '餐饮', '午餐', ''); -INSERT INTO bill.Bills (id, type, date, money, cls, label, options) -VALUES (3353, 'INCOME', '2022-07-04', '9.0', '餐饮', '饮料', ''); -INSERT INTO bill.Bills (id, type, date, money, cls, label, options) -VALUES (3354, 'INCOME', '2022-07-04', '17.0', '餐饮', '早餐', ''); -INSERT INTO bill.Bills (id, type, date, money, cls, label, options) -VALUES (3355, 'INCOME', '2022-07-04', '10.3', '餐饮', '零食', ''); -INSERT INTO bill.Bills (id, type, date, money, cls, label, options) -VALUES (3356, 'INCOME', '2022-07-05', '9.5', '餐饮', '早餐', ''); -INSERT INTO bill.Bills (id, type, date, money, cls, label, options) -VALUES (3357, 'INCOME', '2022-07-05', '22.0', '餐饮', '午餐', ''); -INSERT INTO bill.Bills (id, type, date, money, cls, label, options) -VALUES (3358, 'INCOME', '2022-07-05', '16.0', '餐饮', '晚餐', ''); -INSERT INTO bill.Bills (id, type, date, money, cls, label, options) -VALUES (3359, 'INCOME', '2022-07-05', '1.6', '交通', '公交', ''); -INSERT INTO bill.Bills (id, type, date, money, cls, label, options) -VALUES (3360, 'INCOME', '2022-07-06', '7.0', '餐饮', '早餐', ''); -INSERT INTO bill.Bills (id, type, date, money, cls, label, options) -VALUES (3361, 'INCOME', '2022-07-06', '19.0', '餐饮', '午餐', ''); -INSERT INTO bill.Bills (id, type, date, money, cls, label, options) -VALUES (3362, 'INCOME', '2022-07-06', '6.0', '餐饮', '饮料', ''); -INSERT INTO bill.Bills (id, type, date, money, cls, label, options) -VALUES (3363, 'INCOME', '2022-07-06', '14.0', '餐饮', '晚餐', ''); -INSERT INTO bill.Bills (id, type, date, money, cls, label, options) -VALUES (3364, 'INCOME', '2022-07-06', '1.6', '交通', '公交', ''); -INSERT INTO bill.Bills (id, type, date, money, cls, label, options) -VALUES (3365, 'INCOME', '2022-07-06', '1.6', '交通', '公交', ''); -INSERT INTO bill.Bills (id, type, date, money, cls, label, options) -VALUES (3366, 'INCOME', '2022-07-06', '16.0', '餐饮', '奶茶', ''); -INSERT INTO bill.Bills (id, type, date, money, cls, label, options) -VALUES (3367, 'INCOME', '2022-07-07', '9.0', '餐饮', '早餐', ''); -INSERT INTO bill.Bills (id, type, date, money, cls, label, options) -VALUES (3368, 'INCOME', '2022-07-07', '14.4', '餐饮', '午餐', ''); -INSERT INTO bill.Bills (id, type, date, money, cls, label, options) -VALUES (3369, 'INCOME', '2022-07-07', '1.6', '交通', '公交', ''); -INSERT INTO bill.Bills (id, type, date, money, cls, label, options) -VALUES (3370, 'INCOME', '2022-07-07', '9.0', '餐饮', '晚餐', ''); \ No newline at end of file diff --git a/scripts/migrations.sql b/scripts/migrations.sql index ce06cbc..77f5156 100644 --- a/scripts/migrations.sql +++ b/scripts/migrations.sql @@ -1,46 +1,16 @@ --- In this script, 'dmca' stands for 'Docker MariaDB Clean Arch'. -DROP DATABASE IF EXISTS fiber_dmca; -CREATE DATABASE IF NOT EXISTS fiber_dmca; -USE fiber_dmca; +INSERT INTO labels (id, type, name, count) +VALUES (1, '', 'bill', 0), + (2, '', 'bill', 0), + (3, '', 'bill', 0), + (4, '', 'bill', 0), + (5, '', 'bill', 0), + (6, '', 'bill', 0), + (7, '', 'bill', 0); --- Create a sample table. -CREATE TABLE users ( - id INT NOT NULL AUTO_INCREMENT, - name VARCHAR(255) NOT NULL, - address VARCHAR(255) NOT NULL, - created VARCHAR(255) NOT NULL, - modified VARCHAR(255) NOT NULL, - PRIMARY KEY (id) -) ENGINE=InnoDB CHARACTER SET utf8; - --- Populate table with 10 users. -INSERT INTO users VALUES -(1, 'Sayu Ogiwara', 'Hokkaido, Japan', UNIX_TIMESTAMP(), UNIX_TIMESTAMP()), -(2, 'Chizuru Ichinose', 'Tokyo, Japan', UNIX_TIMESTAMP(), UNIX_TIMESTAMP()), -(3, 'Asagi Aiba', 'Kyoto, Japan', UNIX_TIMESTAMP(), UNIX_TIMESTAMP()), -(4, 'Rin Tohsaka', 'Kobe, Japan', UNIX_TIMESTAMP(), UNIX_TIMESTAMP()), -(5, 'Mai Sakurajima', 'Fujisawa, Japan', UNIX_TIMESTAMP(), UNIX_TIMESTAMP()), -(6, 'Aki Adagaki', 'Fukuoka, Japan', UNIX_TIMESTAMP(), UNIX_TIMESTAMP()), -(7, 'Asuna Yuuki', 'Shinagawa, Japan', UNIX_TIMESTAMP(), UNIX_TIMESTAMP()), -(8, 'Ruka Sarashina', 'Gotenba, Japan', UNIX_TIMESTAMP(), UNIX_TIMESTAMP()), -(9, 'Miyuki Shiba', 'Nagano, Japan', UNIX_TIMESTAMP(), UNIX_TIMESTAMP()), -(10, 'Fumino Furuhashi', 'Niigata, Japan', UNIX_TIMESTAMP(), UNIX_TIMESTAMP()); - --- Create another sample table. -CREATE TABLE cities ( - id INT NOT NULL AUTO_INCREMENT, - name VARCHAR(255) NOT NULL, - created VARCHAR(255) NOT NULL, - modified VARCHAR(255) NOT NULL, - user INT NOT NULL, - PRIMARY KEY (id), - FOREIGN KEY (user) REFERENCES users (id) -) ENGINE=InnoDB CHARACTER SET utf8; - --- Create five data samples. -INSERT INTO cities VALUES -(1, 'Hokkaido', UNIX_TIMESTAMP(), UNIX_TIMESTAMP(), 1), -(2, 'Tokyo', UNIX_TIMESTAMP(), UNIX_TIMESTAMP(), 1), -(3, 'Kyoto', UNIX_TIMESTAMP(), UNIX_TIMESTAMP(), 1), -(4, 'Osaka', UNIX_TIMESTAMP(), UNIX_TIMESTAMP(), 2), -(5, 'Fukuoka', UNIX_TIMESTAMP(), UNIX_TIMESTAMP(), 3); +INSERT INTO bills (year, month, day, money, label) +VALUES (2023, 5, 27, 55, "餐饮"), + (2023, 5, 27, 55, "餐饮"), + (2023, 5, 30, 51, "生活"), + (2023, 5, 30, 51, "生活"), + (2023, 5, 30, 51, "生活"), + (2023, 5, 30, 52, "餐饮"); diff --git a/scripts/sqliteMigrations.sql b/scripts/sqliteMigrations.sql deleted file mode 100644 index 77f5156..0000000 --- a/scripts/sqliteMigrations.sql +++ /dev/null @@ -1,16 +0,0 @@ -INSERT INTO labels (id, type, name, count) -VALUES (1, '', 'bill', 0), - (2, '', 'bill', 0), - (3, '', 'bill', 0), - (4, '', 'bill', 0), - (5, '', 'bill', 0), - (6, '', 'bill', 0), - (7, '', 'bill', 0); - -INSERT INTO bills (year, month, day, money, label) -VALUES (2023, 5, 27, 55, "餐饮"), - (2023, 5, 27, 55, "餐饮"), - (2023, 5, 30, 51, "生活"), - (2023, 5, 30, 51, "生活"), - (2023, 5, 30, 51, "生活"), - (2023, 5, 30, 52, "餐饮");