feat: add run.ps1 script to start projects easily
add a powershell script that supports starting MES, WMS, WMSClient, Workstation and Dashboard projects with one command, includes build and run logic for backend services and npm dev for dashboard
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
package db
|
||||
|
||||
import (
|
||||
"context"
|
||||
"database/sql"
|
||||
"fmt"
|
||||
"time"
|
||||
@@ -54,4 +55,43 @@ func NewDB(c DatabaseConf) (*sql.DB, error) {
|
||||
return nil, err
|
||||
}
|
||||
return sqlDB, nil
|
||||
}
|
||||
}
|
||||
|
||||
// AutoMigrate 执行 ent 自动建表/补齐(只增,不删数据)。供命令行 migrate 使用。
|
||||
|
||||
func AutoMigrate(c DatabaseConf) error {
|
||||
client, sqlDB := MustNewDB(c)
|
||||
defer sqlDB.Close()
|
||||
return client.Schema.Create(context.Background())
|
||||
}
|
||||
|
||||
// DropAllTables 清空 public schema 下所有业务表(破坏性,仅供命令行 reset-all 使用)。
|
||||
func DropAllTables(c DatabaseConf) error {
|
||||
sqlDB, err := NewDB(c)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer sqlDB.Close()
|
||||
|
||||
rows, err := sqlDB.Query(`SELECT tablename FROM pg_tables WHERE schemaname='public'`)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
var names []string
|
||||
for rows.Next() {
|
||||
var t string
|
||||
if err := rows.Scan(&t); err != nil {
|
||||
rows.Close()
|
||||
return err
|
||||
}
|
||||
names = append(names, t)
|
||||
}
|
||||
rows.Close()
|
||||
|
||||
for _, t := range names {
|
||||
if _, err := sqlDB.Exec(`DROP TABLE IF EXISTS "` + t + `" CASCADE`); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user