Skip to content

Commit

Permalink
bugfix:postgresql增加显示指定template
Browse files Browse the repository at this point in the history
  • Loading branch information
xue-ding-e committed Dec 7, 2024
1 parent 78ddb9b commit ed0bbfd
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 2 deletions.
1 change: 1 addition & 0 deletions server/model/system/request/sys_init.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ type InitDB struct {
Password string `json:"password"` // 数据库密码
DBName string `json:"dbName" binding:"required"` // 数据库名
DBPath string `json:"dbPath"` // sqlite数据库文件路径
Template string `json:"template"` // postgresql指定template
}

// MysqlEmptyDsn msyql 空数据库 建库链接
Expand Down
7 changes: 6 additions & 1 deletion server/service/system/sys_initdb_pgsql.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,12 @@ func (h PgsqlInitHandler) EnsureDB(ctx context.Context, conf *request.InitDB) (n
} // 如果没有数据库名, 则跳出初始化数据

dsn := conf.PgsqlEmptyDsn()
createSql := fmt.Sprintf("CREATE DATABASE %s;", c.Dbname)
var createSql string
if conf.Template != "" {
createSql = fmt.Sprintf("CREATE DATABASE %s WITH TEMPLATE %s;", c.Dbname, conf.Template)
} else {
createSql = fmt.Sprintf("CREATE DATABASE %s;", c.Dbname)
}
if err = createDatabase(dsn, "pgx", createSql); err != nil {
return nil, err
} // 创建数据库
Expand Down
9 changes: 8 additions & 1 deletion web/src/view/init/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,12 @@
placeholder="请输入sqlite数据库文件存放路径"
/>
</el-form-item>
<el-form-item v-if="form.dbType === 'pgsql'" label="template">
<el-input
v-model="form.template"
placeholder="请输入postgresql指定template"
/>
</el-form-item>
<el-form-item>
<div style="text-align: right">
<el-button type="primary" @click="onSubmit">立即初始化</el-button>
Expand Down Expand Up @@ -192,7 +198,8 @@
userName: 'postgres',
password: '',
dbName: 'gva',
dbPath: ''
dbPath: '',
template: 'template0'
})
break
case 'oracle':
Expand Down

0 comments on commit ed0bbfd

Please sign in to comment.