Skip to content

Commit

Permalink
feat: add ModelTableExpr to TruncateTableQuery (#969)
Browse files Browse the repository at this point in the history
* feat: add ModelTableExpr for TruncateTableQuery
  • Loading branch information
JunNishimura authored Apr 3, 2024
1 parent 9f78e0d commit 7bc330f
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
5 changes: 4 additions & 1 deletion migrate/migrator.go
Original file line number Diff line number Diff line change
Expand Up @@ -362,7 +362,10 @@ func (m *Migrator) MarkUnapplied(ctx context.Context, migration *Migration) erro
}

func (m *Migrator) TruncateTable(ctx context.Context) error {
_, err := m.db.NewTruncateTable().TableExpr(m.table).Exec(ctx)
_, err := m.db.NewTruncateTable().
Model((*Migration)(nil)).
ModelTableExpr(m.table).
Exec(ctx)
return err
}

Expand Down
5 changes: 5 additions & 0 deletions query_table_truncate.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,11 @@ func (q *TruncateTableQuery) TableExpr(query string, args ...interface{}) *Trunc
return q
}

func (q *TruncateTableQuery) ModelTableExpr(query string, args ...interface{}) *TruncateTableQuery {
q.modelTableName = schema.SafeQuery(query, args)
return q
}

//------------------------------------------------------------------------------

func (q *TruncateTableQuery) ContinueIdentity() *TruncateTableQuery {
Expand Down

0 comments on commit 7bc330f

Please sign in to comment.