2020-07-08 15:39:23 +08:00
|
|
|
package comm
|
|
|
|
|
|
|
|
import (
|
|
|
|
"bytes"
|
2020-09-30 15:58:22 +08:00
|
|
|
"gokins/model"
|
|
|
|
|
2020-07-08 15:39:23 +08:00
|
|
|
"github.com/go-xorm/xorm"
|
|
|
|
_ "github.com/mattn/go-sqlite3"
|
|
|
|
)
|
|
|
|
|
|
|
|
func InitDb() error {
|
|
|
|
db, err := xorm.NewEngine("sqlite3", Dir+"/db.dat")
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
Db = db
|
2020-09-29 22:35:32 +08:00
|
|
|
isext, err := Db.IsTableExist(model.SysUser{})
|
2020-07-08 15:39:23 +08:00
|
|
|
if err == nil && !isext {
|
2020-09-29 22:35:32 +08:00
|
|
|
_, err := Db.Import(bytes.NewBufferString(sqls))
|
|
|
|
if err != nil {
|
|
|
|
println("Db.Import err:" + err.Error())
|
|
|
|
}
|
2020-07-08 15:39:23 +08:00
|
|
|
//e:=&models.SysUser{}
|
|
|
|
//e.Times=time.Now()
|
|
|
|
//db.Cols("times").Where("xid=?","admin").Update(e)
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
const sqls = `
|
|
|
|
/*
|
|
|
|
Navicat Premium Data Transfer
|
|
|
|
|
2020-09-29 22:35:32 +08:00
|
|
|
Source Server : gokinsdb
|
2020-07-08 15:39:23 +08:00
|
|
|
Source Server Type : SQLite
|
|
|
|
Source Server Version : 3030001
|
|
|
|
Source Schema : main
|
|
|
|
|
|
|
|
Target Server Type : SQLite
|
|
|
|
Target Server Version : 3030001
|
|
|
|
File Encoding : 65001
|
|
|
|
|
2020-10-02 16:04:26 +08:00
|
|
|
Date: 02/10/2020 16:02:56
|
2020-07-08 15:39:23 +08:00
|
|
|
*/
|
|
|
|
|
|
|
|
PRAGMA foreign_keys = false;
|
|
|
|
|
2020-09-30 20:26:50 +08:00
|
|
|
-- ----------------------------
|
|
|
|
-- Table structure for sys_param
|
|
|
|
-- ----------------------------
|
|
|
|
DROP TABLE IF EXISTS "sys_param";
|
|
|
|
CREATE TABLE "sys_param" (
|
|
|
|
"id" integer NOT NULL PRIMARY KEY AUTOINCREMENT,
|
|
|
|
"key" varchar,
|
|
|
|
"cont" blob,
|
|
|
|
"times" datetime
|
|
|
|
);
|
|
|
|
|
|
|
|
-- ----------------------------
|
|
|
|
-- Records of sys_param
|
|
|
|
-- ----------------------------
|
|
|
|
BEGIN;
|
|
|
|
COMMIT;
|
|
|
|
|
2020-07-08 15:39:23 +08:00
|
|
|
-- ----------------------------
|
|
|
|
-- Table structure for sys_user
|
|
|
|
-- ----------------------------
|
|
|
|
DROP TABLE IF EXISTS "sys_user";
|
|
|
|
CREATE TABLE "sys_user" (
|
|
|
|
"id" integer,
|
|
|
|
"xid" text NOT NULL,
|
|
|
|
"name" text NOT NULL,
|
|
|
|
"pass" text,
|
|
|
|
"nick" text,
|
|
|
|
"phone" text,
|
|
|
|
"times" datetime,
|
|
|
|
"logintm" datetime,
|
|
|
|
"fwtm" datetime,
|
|
|
|
"avat" text,
|
|
|
|
PRIMARY KEY ("id")
|
|
|
|
);
|
|
|
|
|
|
|
|
-- ----------------------------
|
|
|
|
-- Records of sys_user
|
|
|
|
-- ----------------------------
|
2020-09-29 22:35:32 +08:00
|
|
|
BEGIN;
|
2020-07-08 15:39:23 +08:00
|
|
|
INSERT INTO "sys_user" VALUES (1, 'admin', 'root', NULL, '超级管理员', NULL, '2020-07-08 07:25:53', NULL, NULL, NULL);
|
2020-09-29 22:35:32 +08:00
|
|
|
COMMIT;
|
|
|
|
|
|
|
|
-- ----------------------------
|
|
|
|
-- Table structure for t_model
|
|
|
|
-- ----------------------------
|
|
|
|
DROP TABLE IF EXISTS "t_model";
|
|
|
|
CREATE TABLE "t_model" (
|
|
|
|
"id" integer NOT NULL PRIMARY KEY AUTOINCREMENT,
|
2020-09-30 15:58:22 +08:00
|
|
|
"uid" varchar,
|
2020-09-29 22:35:32 +08:00
|
|
|
"title" text,
|
|
|
|
"desc" text,
|
|
|
|
"times" datetime,
|
2020-10-02 16:04:26 +08:00
|
|
|
"del" integer DEFAULT 0,
|
|
|
|
"envs" text,
|
|
|
|
"wrkdir" text
|
2020-09-29 22:35:32 +08:00
|
|
|
);
|
|
|
|
|
|
|
|
-- ----------------------------
|
|
|
|
-- Records of t_model
|
|
|
|
-- ----------------------------
|
|
|
|
BEGIN;
|
|
|
|
COMMIT;
|
|
|
|
|
|
|
|
-- ----------------------------
|
|
|
|
-- Table structure for t_model_run
|
|
|
|
-- ----------------------------
|
|
|
|
DROP TABLE IF EXISTS "t_model_run";
|
|
|
|
CREATE TABLE "t_model_run" (
|
|
|
|
"id" integer NOT NULL PRIMARY KEY AUTOINCREMENT,
|
2020-09-30 15:58:22 +08:00
|
|
|
"uid" varchar,
|
2020-09-29 22:35:32 +08:00
|
|
|
"tid" integer,
|
|
|
|
"times" datetime,
|
|
|
|
"timesd" datetime,
|
2020-10-02 16:04:26 +08:00
|
|
|
"state" integer,
|
|
|
|
"errs" text
|
2020-09-29 22:35:32 +08:00
|
|
|
);
|
|
|
|
|
|
|
|
-- ----------------------------
|
|
|
|
-- Records of t_model_run
|
|
|
|
-- ----------------------------
|
|
|
|
BEGIN;
|
|
|
|
COMMIT;
|
|
|
|
|
|
|
|
-- ----------------------------
|
|
|
|
-- Table structure for t_output
|
|
|
|
-- ----------------------------
|
|
|
|
DROP TABLE IF EXISTS "t_output";
|
|
|
|
CREATE TABLE "t_output" (
|
|
|
|
"id" integer NOT NULL PRIMARY KEY AUTOINCREMENT,
|
|
|
|
"type" varchar(50),
|
|
|
|
"tid" integer,
|
|
|
|
"output" text,
|
|
|
|
"times" datetime
|
|
|
|
);
|
|
|
|
|
|
|
|
-- ----------------------------
|
|
|
|
-- Records of t_output
|
|
|
|
-- ----------------------------
|
|
|
|
BEGIN;
|
|
|
|
COMMIT;
|
|
|
|
|
|
|
|
-- ----------------------------
|
2020-09-30 20:26:50 +08:00
|
|
|
-- Table structure for t_plugin
|
2020-09-29 22:35:32 +08:00
|
|
|
-- ----------------------------
|
2020-09-30 20:26:50 +08:00
|
|
|
DROP TABLE IF EXISTS "t_plugin";
|
|
|
|
CREATE TABLE "t_plugin" (
|
2020-09-29 22:35:32 +08:00
|
|
|
"id" integer NOT NULL PRIMARY KEY AUTOINCREMENT,
|
|
|
|
"tid" integer NOT NULL,
|
|
|
|
"title" text,
|
|
|
|
"type" integer DEFAULT 0,
|
|
|
|
"para" text,
|
|
|
|
"cont" text,
|
2020-09-30 20:26:50 +08:00
|
|
|
"times" datetime,
|
|
|
|
"sort" integer DEFAULT 100,
|
2020-10-02 16:04:26 +08:00
|
|
|
"del" integer DEFAULT 0,
|
|
|
|
"exend" integer DEFAULT 0
|
2020-09-29 22:35:32 +08:00
|
|
|
);
|
|
|
|
|
|
|
|
-- ----------------------------
|
2020-09-30 20:26:50 +08:00
|
|
|
-- Records of t_plugin
|
2020-09-29 22:35:32 +08:00
|
|
|
-- ----------------------------
|
|
|
|
BEGIN;
|
|
|
|
COMMIT;
|
|
|
|
|
|
|
|
-- ----------------------------
|
2020-09-30 20:26:50 +08:00
|
|
|
-- Table structure for t_plugin_run
|
2020-09-29 22:35:32 +08:00
|
|
|
-- ----------------------------
|
2020-09-30 20:26:50 +08:00
|
|
|
DROP TABLE IF EXISTS "t_plugin_run";
|
|
|
|
CREATE TABLE "t_plugin_run" (
|
2020-09-29 22:35:32 +08:00
|
|
|
"id" integer NOT NULL PRIMARY KEY AUTOINCREMENT,
|
|
|
|
"pid" integer,
|
2020-09-30 20:26:50 +08:00
|
|
|
"mid" integer,
|
2020-09-29 22:35:32 +08:00
|
|
|
"tid" integer,
|
|
|
|
"times" datetime,
|
|
|
|
"timesd" datetime,
|
|
|
|
"state" integer,
|
|
|
|
"excode" integer,
|
|
|
|
"output" text
|
|
|
|
);
|
|
|
|
|
|
|
|
-- ----------------------------
|
2020-09-30 20:26:50 +08:00
|
|
|
-- Records of t_plugin_run
|
2020-09-29 22:35:32 +08:00
|
|
|
-- ----------------------------
|
|
|
|
BEGIN;
|
|
|
|
COMMIT;
|
2020-07-08 15:39:23 +08:00
|
|
|
|
2020-09-30 20:26:50 +08:00
|
|
|
-- ----------------------------
|
|
|
|
-- Auto increment value for sys_param
|
|
|
|
-- ----------------------------
|
|
|
|
|
|
|
|
-- ----------------------------
|
|
|
|
-- Indexes structure for table sys_param
|
|
|
|
-- ----------------------------
|
|
|
|
CREATE INDEX "main"."key"
|
|
|
|
ON "sys_param" (
|
|
|
|
"key" ASC
|
|
|
|
);
|
|
|
|
|
2020-07-08 15:39:23 +08:00
|
|
|
-- ----------------------------
|
|
|
|
-- Indexes structure for table sys_user
|
|
|
|
-- ----------------------------
|
2020-09-29 22:35:32 +08:00
|
|
|
CREATE INDEX "main"."IDX_sys_user_phone"
|
2020-07-08 15:39:23 +08:00
|
|
|
ON "sys_user" (
|
|
|
|
"phone" ASC
|
|
|
|
);
|
2020-09-29 22:35:32 +08:00
|
|
|
CREATE INDEX "main"."name"
|
2020-07-08 15:39:23 +08:00
|
|
|
ON "sys_user" (
|
|
|
|
"name" ASC
|
|
|
|
);
|
2020-09-29 22:35:32 +08:00
|
|
|
CREATE INDEX "main"."xid"
|
2020-07-08 15:39:23 +08:00
|
|
|
ON "sys_user" (
|
|
|
|
"xid" ASC
|
|
|
|
);
|
|
|
|
|
2020-09-29 22:35:32 +08:00
|
|
|
-- ----------------------------
|
|
|
|
-- Auto increment value for t_model
|
|
|
|
-- ----------------------------
|
|
|
|
|
|
|
|
-- ----------------------------
|
|
|
|
-- Auto increment value for t_model_run
|
|
|
|
-- ----------------------------
|
|
|
|
|
|
|
|
-- ----------------------------
|
|
|
|
-- Auto increment value for t_output
|
|
|
|
-- ----------------------------
|
|
|
|
|
|
|
|
-- ----------------------------
|
|
|
|
-- Indexes structure for table t_output
|
|
|
|
-- ----------------------------
|
|
|
|
CREATE INDEX "main"."kv"
|
|
|
|
ON "t_output" (
|
|
|
|
"type" ASC,
|
|
|
|
"tid" ASC
|
|
|
|
);
|
|
|
|
|
|
|
|
-- ----------------------------
|
2020-09-30 20:26:50 +08:00
|
|
|
-- Auto increment value for t_plugin
|
2020-09-29 22:35:32 +08:00
|
|
|
-- ----------------------------
|
|
|
|
|
|
|
|
-- ----------------------------
|
2020-09-30 20:26:50 +08:00
|
|
|
-- Auto increment value for t_plugin_run
|
2020-09-29 22:35:32 +08:00
|
|
|
-- ----------------------------
|
|
|
|
|
2020-07-08 15:39:23 +08:00
|
|
|
PRAGMA foreign_keys = true;
|
2020-09-29 22:35:32 +08:00
|
|
|
|
2020-07-08 15:39:23 +08:00
|
|
|
`
|