This commit is contained in:
shoopea 2019-05-11 15:48:39 +08:00
parent 0d331298ba
commit 9410554e7a

21
sql.go
View File

@ -42,7 +42,7 @@ func initDB() {
err = tx.Commit()
failOnError(err, "initDB : commit cleanup")
log.Println("Database cleaned up")
log.Println("initDB : Database cleaned up")
_, err = db.Exec(`CREATE TABLE code_obj_type (
id SMALLINT UNSIGNED NOT NULL
@ -51,6 +51,7 @@ func initDB() {
,PRIMARY KEY (id)
) ENGINE = InnoDB CHARSET=utf8mb4 COLLATE utf8mb4_unicode_ci;`)
failOnError(err, "initDB : create table code_obj_type")
log.Println("initDB : code_obj_type created ...")
_, err = db.Exec(`CREATE TABLE code_obj_sub_type (
id SMALLINT UNSIGNED NOT NULL
@ -61,6 +62,7 @@ func initDB() {
,FOREIGN KEY (obj_type_id) REFERENCES code_obj_type(id) ON DELETE CASCADE
) ENGINE = InnoDB CHARSET=utf8mb4 COLLATE utf8mb4_unicode_ci;`)
failOnError(err, "initDB : create table code_obj_sub_type")
log.Println("initDB : code_obj_sub_type created ...")
_, err = db.Exec(`CREATE TABLE obj (
id BIGINT UNSIGNED NOT NULL AUTO_INCREMENT
@ -72,6 +74,7 @@ func initDB() {
,FOREIGN KEY (obj_sub_type_id) REFERENCES code_obj_sub_type(id) ON DELETE CASCADE
) ENGINE = InnoDB AUTO_INCREMENT = 0 CHARSET=utf8mb4 COLLATE utf8mb4_unicode_ci;`)
failOnError(err, "initDB : create table obj")
log.Println("initDB : obj created ...")
_, err = db.Exec(`CREATE TABLE obj_user (
obj_id BIGINT UNSIGNED NOT NULL
@ -85,6 +88,7 @@ func initDB() {
,FOREIGN KEY (obj_id) REFERENCES obj(id) ON DELETE CASCADE
) ENGINE = InnoDB CHARSET=utf8mb4 COLLATE utf8mb4_unicode_ci;`)
failOnError(err, "initDB : create table obj_user")
log.Println("initDB : obj_user created ...")
_, err = db.Exec(`CREATE TABLE obj_guild (
obj_id BIGINT UNSIGNED NOT NULL
@ -95,6 +99,7 @@ func initDB() {
,FOREIGN KEY (obj_id) REFERENCES obj(id) ON DELETE CASCADE
) ENGINE = InnoDB CHARSET=utf8mb4 COLLATE utf8mb4_unicode_ci;`)
failOnError(err, "initDB : create table obj_guild")
log.Println("initDB : obj_guild created ...")
_, err = db.Exec(`CREATE TABLE obj_war (
obj_id BIGINT UNSIGNED NOT NULL AUTO_INCREMENT
@ -103,6 +108,7 @@ func initDB() {
,FOREIGN KEY (obj_id) REFERENCES obj(id) ON DELETE CASCADE
) ENGINE = InnoDB CHARSET=utf8mb4 COLLATE utf8mb4_unicode_ci;`)
failOnError(err, "initDB : create table obj_war")
log.Println("initDB : obj_war created ...")
_, err = db.Exec(`CREATE TABLE obj_msg (
obj_id BIGINT UNSIGNED NOT NULL
@ -116,6 +122,7 @@ func initDB() {
,UNIQUE KEY (msg_id, chat_id, sender_user_id)
) ENGINE = InnoDB CHARSET=utf8mb4 COLLATE utf8mb4_unicode_ci;`)
failOnError(err, "initDB : create table obj_msg")
log.Println("initDB : obj_msg created ...")
_, err = db.Exec(`CREATE TABLE obj_msg_report (
obj_id BIGINT UNSIGNED NOT NULL
@ -124,6 +131,7 @@ func initDB() {
,FOREIGN KEY (war_id) REFERENCES obj(id) ON DELETE CASCADE
) ENGINE = InnoDB CHARSET=utf8mb4 COLLATE utf8mb4_unicode_ci;`)
failOnError(err, "initDB : create table obj_msg_report")
log.Println("initDB : obj_msg_report created ...")
_, err = db.Exec(`CREATE TABLE obj_war_report (
obj_id BIGINT UNSIGNED NOT NULL
@ -140,7 +148,8 @@ func initDB() {
,FOREIGN KEY (war_id) REFERENCES obj(id) ON DELETE CASCADE
,UNIQUE KEY (user_id, war_id)
) ENGINE = InnoDB CHARSET=utf8mb4 COLLATE utf8mb4_unicode_ci;`)
failOnError(err, "initDB : create table obj_msg_report")
failOnError(err, "initDB : create table obj_war_report")
log.Println("initDB : obj_war_report created ...")
_, err = db.Exec(`CREATE TABLE obj_msg_auction_announce (
obj_id BIGINT UNSIGNED NOT NULL
@ -157,6 +166,7 @@ func initDB() {
,KEY (lot_id)
) ENGINE = InnoDB CHARSET=utf8mb4 COLLATE utf8mb4_unicode_ci;`)
failOnError(err, "initDB : create table obj_msg_auction_announce")
log.Println("initDB : obj_msg_auction_announce created ...")
_, err = db.Exec(`CREATE TABLE obj_msg_auction_upd_req (
obj_id BIGINT UNSIGNED NOT NULL
@ -165,6 +175,7 @@ func initDB() {
,KEY (lot_id)
) ENGINE = InnoDB CHARSET=utf8mb4 COLLATE utf8mb4_unicode_ci;`)
failOnError(err, "initDB : create table obj_msg_auction_upd_req")
log.Println("initDB : obj_msg_auction_upd_req created ...")
_, err = db.Exec(`CREATE TABLE obj_msg_auction_upd_ack (
obj_id BIGINT UNSIGNED NOT NULL
@ -173,7 +184,8 @@ func initDB() {
,item VARCHAR(80)
,FOREIGN KEY (obj_id) REFERENCES obj(id) ON DELETE CASCADE
) ENGINE = InnoDB CHARSET=utf8mb4 COLLATE utf8mb4_unicode_ci;`)
failOnError(err, "initDB : create table obj_msg_auction_upd_req")
failOnError(err, "initDB : create table obj_msg_auction_upd_ack")
log.Println("initDB : obj_msg_auction_upd_ack created ...")
_, err = db.Exec(`CREATE TABLE msg_rules (
id SMALLINT UNSIGNED NOT NULL AUTO_INCREMENT
@ -184,6 +196,7 @@ func initDB() {
,UNIQUE KEY (id)
) ENGINE = InnoDB CHARSET=utf8mb4 COLLATE utf8mb4_unicode_ci;`)
failOnError(err, "initDB : create table msg_rules")
log.Println("initDB : msg_rules created ...")
_, err = db.Exec(`CREATE TABLE obj_item (
obj_id BIGINT UNSIGNED NOT NULL
@ -194,6 +207,7 @@ func initDB() {
,UNIQUE KEY (intl_id)
) ENGINE = InnoDB CHARSET=utf8mb4 COLLATE utf8mb4_unicode_ci;`)
failOnError(err, "initDB : create table obj_item")
log.Println("initDB : obj_item created ...")
_, err = db.Exec(`CREATE TABLE obj_job (
obj_id BIGINT UNSIGNED NOT NULL
@ -210,6 +224,7 @@ func initDB() {
,FOREIGN KEY (obj_id) REFERENCES obj(id) ON DELETE CASCADE
) ENGINE = InnoDB CHARSET=utf8mb4 COLLATE utf8mb4_unicode_ci;`)
failOnError(err, "initDB : create table obj_job")
log.Println("initDB : obj_job created ...")
_, err = db.Exec(`INSERT INTO code_obj_type (id, intl_id, name)
VALUES (` + strconv.Itoa(objTypeUser) + `, "user", "User")