From 7bc330f152cf0d9dc30956478e2731ea5816f012 Mon Sep 17 00:00:00 2001
From: Jun Nishimura <n.junjun0303@gmail.com>
Date: Wed, 3 Apr 2024 15:00:08 +0900
Subject: [PATCH] feat: add ModelTableExpr to TruncateTableQuery (#969)

* feat: add ModelTableExpr for TruncateTableQuery
---
 migrate/migrator.go     | 5 ++++-
 query_table_truncate.go | 5 +++++
 2 files changed, 9 insertions(+), 1 deletion(-)

diff --git a/migrate/migrator.go b/migrate/migrator.go
index 33c5bd16f..e6d70e39f 100644
--- a/migrate/migrator.go
+++ b/migrate/migrator.go
@@ -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
 }
 
diff --git a/query_table_truncate.go b/query_table_truncate.go
index a704b7b10..9ac5599d9 100644
--- a/query_table_truncate.go
+++ b/query_table_truncate.go
@@ -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 {