FIX: code too complicated
This commit is contained in:
parent
805f319578
commit
5cfe04e5f5
|
|
@ -160,7 +160,7 @@ func createDatabase(dsn string, driver string, createSql string) error {
|
|||
// createTables 创建表(默认 dbInitHandler.initTables 行为)
|
||||
func createTables(ctx context.Context, inits initSlice) error {
|
||||
next, cancel := context.WithCancel(ctx)
|
||||
defer func(c func()) { c() }(cancel)
|
||||
defer cancel()
|
||||
for _, init := range inits {
|
||||
if init.TableCreated(next) {
|
||||
continue
|
||||
|
|
|
|||
|
|
@ -73,7 +73,7 @@ func (h MssqlInitHandler) InitTables(ctx context.Context, inits initSlice) error
|
|||
|
||||
func (h MssqlInitHandler) InitData(ctx context.Context, inits initSlice) error {
|
||||
next, cancel := context.WithCancel(ctx)
|
||||
defer func(c func()) { c() }(cancel)
|
||||
defer cancel()
|
||||
for _, init := range inits {
|
||||
if init.DataInserted(next) {
|
||||
color.Info.Printf(InitDataExist, Mssql, init.InitializerName())
|
||||
|
|
|
|||
|
|
@ -78,7 +78,7 @@ func (h MysqlInitHandler) InitTables(ctx context.Context, inits initSlice) error
|
|||
|
||||
func (h MysqlInitHandler) InitData(ctx context.Context, inits initSlice) error {
|
||||
next, cancel := context.WithCancel(ctx)
|
||||
defer func(c func()) { c() }(cancel)
|
||||
defer cancel()
|
||||
for _, init := range inits {
|
||||
if init.DataInserted(next) {
|
||||
color.Info.Printf(InitDataExist, Mysql, init.InitializerName())
|
||||
|
|
|
|||
|
|
@ -82,7 +82,7 @@ func (h PgsqlInitHandler) InitTables(ctx context.Context, inits initSlice) error
|
|||
|
||||
func (h PgsqlInitHandler) InitData(ctx context.Context, inits initSlice) error {
|
||||
next, cancel := context.WithCancel(ctx)
|
||||
defer func(c func()) { c() }(cancel)
|
||||
defer cancel()
|
||||
for i := 0; i < len(inits); i++ {
|
||||
if inits[i].DataInserted(next) {
|
||||
color.Info.Printf(InitDataExist, Pgsql, inits[i].InitializerName())
|
||||
|
|
|
|||
|
|
@ -69,7 +69,7 @@ func (h SqliteInitHandler) InitTables(ctx context.Context, inits initSlice) erro
|
|||
|
||||
func (h SqliteInitHandler) InitData(ctx context.Context, inits initSlice) error {
|
||||
next, cancel := context.WithCancel(ctx)
|
||||
defer func(c func()) { c() }(cancel)
|
||||
defer cancel()
|
||||
for _, init := range inits {
|
||||
if init.DataInserted(next) {
|
||||
color.Info.Printf(InitDataExist, Sqlite, init.InitializerName())
|
||||
|
|
|
|||
Loading…
Reference in New Issue