add global config support
This commit is contained in:
parent
cd1e1a42f3
commit
34d553a890
23 changed files with 1682 additions and 343 deletions
23
db/db.go
23
db/db.go
|
|
@ -44,6 +44,15 @@ type UsersTable struct {
|
|||
UpdatedAt int64 `json:"updated_at"`
|
||||
}
|
||||
|
||||
// GlobalConfig 全局CaddyFile配置专用table
|
||||
type GlobalConfig struct {
|
||||
Filename string `json:"filename"`
|
||||
Params []byte `json:"params"`
|
||||
TmplContent []byte `json:"tmpl_content"`
|
||||
RenderedContent []byte `json:"rendered_content"`
|
||||
UpdatedAt int64 `json:"updated_at"`
|
||||
}
|
||||
|
||||
// ConfigDB
|
||||
type ConfigDB struct {
|
||||
DB *sql.DB
|
||||
|
|
@ -124,7 +133,6 @@ func (cdb *ConfigDB) createTables() error {
|
|||
return fmt.Errorf("failed to create 'rendered_configs' table: %w", err)
|
||||
}
|
||||
|
||||
//
|
||||
// 4. 创建 users 表
|
||||
_, err = tx.Exec(`
|
||||
CREATE TABLE IF NOT EXISTS users (
|
||||
|
|
@ -137,6 +145,19 @@ func (cdb *ConfigDB) createTables() error {
|
|||
return fmt.Errorf("failed to create 'users' table: %w", err)
|
||||
}
|
||||
|
||||
// 5. 创建 global_configs 表
|
||||
_, err = tx.Exec(`
|
||||
CREATE TABLE IF NOT EXISTS global_configs (
|
||||
filename TEXT PRIMARY KEY,
|
||||
params BLOB NOT NULL DEFAULT '',
|
||||
tmpl_content BLOB NOT NULL DEFAULT '',
|
||||
rendered_content BLOB NOT NULL DEFAULT '',
|
||||
updated_at INTEGER NOT NULL DEFAULT (strftime('%s', 'now'))
|
||||
);`)
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to create 'global_configs' table: %w", err)
|
||||
}
|
||||
|
||||
// 提交事务
|
||||
if err := tx.Commit(); err != nil {
|
||||
return fmt.Errorf("failed to commit transaction for table creation: %w", err)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue