Commit 0eb0a727 authored by wanli's avatar wanli

🎈 perf(): 优化启动脚本以及迁移工具

parent 9efe94e6
#!/usr/bin/env bash
###
# @Author: your name
# @Date: 2021-07-15 09:33:39
# @LastEditTime: 2021-07-21 14:25:03
# @LastEditors: Please set LastEditors
# @Description: In User Settings Edit
# @FilePath: \evm-store\backend\run.sh
###
# 获取当前路径
Cur_Dir=$(pwd)
......@@ -26,4 +34,4 @@ supervisorctl start evm_store
Cur_Dir=$(pwd)
source venv/bin/activate
nohup ${Cur_Dir}/venv/bin/python3 ${Cur_Dir}/start.py > runoob.log 2>&1 &
nohup ${Cur_Dir}/venv/bin/python3 ${Cur_Dir}/start.py > running.log 2>&1 &
#!/usr/bin/env bash
###
# @Author: your name
# @Date: 2021-07-15 09:33:39
# @LastEditTime: 2021-07-21 14:25:13
# @LastEditors: your name
# @Description: In User Settings Edit
# @FilePath: \evm-store\backend\start.sh
###
Cur_Dir=$(pwd)
source venv/bin/activate
nohup ${Cur_Dir}/venv/bin/python3 ${Cur_Dir}/start.py > runoob.log 2>&1 &
nohup ${Cur_Dir}/venv/bin/python3 ${Cur_Dir}/start.py > running.log 2>&1 &
/*
* @Author: your name
* @Date: 2021-07-21 13:02:17
* @LastEditTime: 2021-07-21 13:09:34
* @LastEditors: Please set LastEditors
* @Description: In User Settings Edit
* @FilePath: \evm-store\tools\database_migration.go
*/
package main
import (
"database/sql"
"fmt"
_ "github.com/mattn/go-sqlite3"
)
func main() {
fmt.Println("打开数据")
db, err := sql.Open("sqlite3", "./evue_store.db")
checkErr(err)
fmt.Println("生成数据表")
sql_table := `
CREATE TABLE IF NOT EXISTS "userinfo" (
"uid" INTEGER PRIMARY KEY AUTOINCREMENT,
"username" VARCHAR(64) NULL,
"departname" VARCHAR(64) NULL,
"created" TIMESTAMP default (datetime('now', 'localtime'))
);
CREATE TABLE IF NOT EXISTS "userdeatail" (
"uid" INT(10) NULL,
"intro" TEXT NULL,
"profile" TEXT NULL,
PRIMARY KEY (uid)
);
`
db.Exec(sql_table)
//插入数据
fmt.Print("插入数据, ID=")
stmt, err := db.Prepare("INSERT INTO userinfo(username, departname) values(?, ?)")
checkErr(err)
res, err := stmt.Exec("astaxie", "研发部门")
checkErr(err)
id, err := res.LastInsertId()
checkErr(err)
fmt.Println(id)
//更新数据
fmt.Print("更新数据 ")
stmt, err = db.Prepare("update userinfo set username=? where uid=?")
checkErr(err)
res, err = stmt.Exec("astaxieupdate", id)
checkErr(err)
affect, err := res.RowsAffected()
checkErr(err)
fmt.Println(affect)
//查询数据
fmt.Println("查询数据")
rows, err := db.Query("SELECT * FROM userinfo")
checkErr(err)
for rows.Next() {
var uid int
var username string
var department string
var created string
err = rows.Scan(&uid, &username, &department, &created)
checkErr(err)
fmt.Println(uid, username, department, created)
}
/*
//删除数据
fmt.Println("删除数据")
stmt, err = db.Prepare("delete from userinfo where uid=?")
checkErr(err)
res, err = stmt.Exec(id)
checkErr(err)
affect, err = res.RowsAffected()
checkErr(err)
fmt.Println(affect)
*/
db.Close()
}
func checkErr(err error) {
if err != nil {
panic(err)
}
}
......@@ -3,7 +3,7 @@
'''
Author: your name
Date: 2021-07-20 19:04:27
LastEditTime: 2021-07-21 10:05:11
LastEditTime: 2021-07-21 13:34:32
LastEditors: Please set LastEditors
Description: In User Settings Edit
FilePath: \evm-store\tools\database_migration.py
......@@ -33,6 +33,8 @@ with open("database_migration.sql", "w+") as fd:
]
sqls = [
"update evm_store_apps set create_by = {a} where create_by = {b};",
"update evm_store_apps set update_by = {a} where update_by = {b};",
"update evm_store_annex set create_by = {a} where create_by = {b};",
"update evm_store_annex set update_by = {a} where update_by = {b};",
"update evm_store_app_logs set create_by = {a} where create_by = {b};",
......@@ -51,7 +53,7 @@ with open("database_migration.sql", "w+") as fd:
# 先插入user表
source_cur.execute('SELECT account, username, password, email, phone, create_at, create_by, update_at, update_by FROM evm_store_user')
sql = "insert into evm_user (id, uuid, account, username, password, email, phone, create_at, create_by, update_at, update_by, is_delete) values ({a}, '{b}', '{c}', '{d}', '{e}', '{f}', '{g}', '{h}', {i}, '{j}', {k}, 0);"
sql = "insert into evm_user (id, uuid, account, username, password, email, phone, create_at, create_by, update_at, update_by, is_delete, role) values ({a}, '{b}', '{c}', '{d}', '{e}', '{f}', '{g}', '{h}', {i}, '{j}', {k}, 0, 0);"
res = source_cur.fetchall()
i = 0
for line in res:
......@@ -65,9 +67,9 @@ with open("database_migration.sql", "w+") as fd:
# login logs
source_cur.execute('SELECT id, username, ip, address, create_at, create_by, remarks FROM evm_store_login_logs')
res = source_cur.fetchall()
sql = "insert into evm_login (id, uuid, user, login_at, user_agent, ip, geo_location, operator, create_at, create_by, update_at, update_by, is_delete) values ({a}, '{b}', {c}, '{d}', '{e}', '{f}', '{g}', '{h}', '{i}', {j}, '{k}', {l}, 0);"
sql = "insert into evm_login (uuid, user, login_at, user_agent, ip, geo_location, operator, create_at, create_by, update_at, update_by, is_delete) values ('{b}', {c}, '{d}', '{e}', '{f}', '{g}', '{h}', '{i}', {j}, '{k}', {l}, 0);"
for line in res:
sql_str = sql.format(a=line[0], b=uuid.uuid1().hex, c=line[5], d=line[6], e="", f=line[2], g=line[3], h="", i=line[4], j=line[5], k=line[4], l=line[5])
sql_str = sql.format(b=uuid.uuid1().hex, c=line[5], d=line[6], e="", f=line[2], g=line[3], h="", i=line[4], j=line[5], k=line[4], l=line[5])
# target_cur.execute(sql_str)
fd.write(sql_str + "\n")
target_conn.commit()
......@@ -78,12 +80,12 @@ with open("database_migration.sql", "w+") as fd:
res = source_cur.fetchall()
for line in res:
sql_str = string = "update evm_store_apps set app_url = '{u}' where id = {a}".format(u=line[1], a=line[0])
# target_cur.execute(sql_str)
fd.write(sql_str + "\n")
source_cur.execute(sql_str)
# fd.write(sql_str + "\n")
target_conn.commit()
# annex
source_cur.execute('SELECT id, uuid, app, title, path, size, create_by, create_at, update_by, update_at, is_delete FROM evm_store_annex')
source_cur.execute('SELECT id, uuid, app, title, path, size, create_at, create_by, update_at, update_by, is_delete FROM evm_store_annex')
res = source_cur.fetchall()
sql = "insert into evm_annex (id, uuid, app, title, path, size, create_at, create_by, update_at, update_by, is_delete) values ({a}, '{b}', {c}, '{d}', '{e}', {f}, '{g}', {h}, '{i}', {j}, 0);"
for line in res:
......@@ -118,7 +120,7 @@ with open("database_migration.sql", "w+") as fd:
res = source_cur.fetchall()
sql = "insert into evm_package (id, uuid, app_name, app_path, app_version, app_info, create_at, create_by, update_at, update_by, is_delete, source) values ({a}, '{b}', '{c}', '{d}', '{e}', '{f}', '{g}', {h}, '{i}', {j}, {k}, {l});"
for line in res:
s = 1 if line[3].find("evueapps") > -1 else 0
s = 1 if line[5] and isinstance(line[5], str) and line[5].find("evueapps") > -1 else 0
sql_str = sql.format(a=line[0], b=uuid.uuid1().hex, c=line[2], d=line[3], e=line[4], f=line[5], g=line[6], h=line[7], i=line[6], j=line[7], k=0, l=s)
# target_cur.execute(sql_str)
fd.write(sql_str + "\n")
......@@ -132,18 +134,18 @@ with open("database_migration.sql", "w+") as fd:
for line in res:
sql_str = "select id, uuid, app_path from evm_store_app_logs where app_path = '{}'".format(line[3])
source_cur.execute(sql_str)
print("%%%%%%%%%%%%%%", sql_str)
tmp = source_cur.fetchone()
print("=======>", line[0])
if tmp:
continue
print("===========>", line)
sql_str = string = "select app_name, app_version from evm_store_apps where id == {id}".format(id=line[2])
sql_str = "select app_name, app_version from evm_store_apps where id == {id}".format(id=line[2])
source_cur.execute(sql_str)
app = source_cur.fetchone()
print("app:", app)
if app:
s = 1 if line[5] and line[5].find("evueapps") > -1 else 0
s = 1 if line[5] and isinstance(line[5], str) and line[5].find("evueapps") > -1 else 0
sql_str = sql.format(a=line[0], b=uuid.uuid1().hex, c=app[0], d=line[3], e=app[1], f=line[4], g=s, h=line[6], i=line[7], j=line[8], k=line[9], l=line[10])
# target_cur.execute(sql_str)
fd.write(sql_str + "\n")
......
module tool
go 1.16
require github.com/mattn/go-sqlite3 v1.14.8
github.com/mattn/go-sqlite3 v1.14.8 h1:gDp86IdQsN/xWjIEmr9MF6o9mpksUgh0fu+9ByFxzIU=
github.com/mattn/go-sqlite3 v1.14.8/go.mod h1:NyWgC/yNuGj7Q9rpYnZvas74GogHl5/Z4A/KQRfk6bU=
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment