Skip to content
This repository was archived by the owner on Dec 24, 2022. It is now read-only.

Commit 30377c1

Browse files
committed
Remove double execution of Drop SQL Scripts
1 parent bf7f0fb commit 30377c1

File tree

2 files changed

+20
-10
lines changed

2 files changed

+20
-10
lines changed

src/ServiceStack.OrmLite/OrmLiteWriteCommandExtensions.cs

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -84,11 +84,6 @@ internal static bool CreateTable(this IDbCommand dbCmd, bool overwrite, Type mod
8484
var tableExists = dialectProvider.DoesTableExist(dbCmd, tableName, schema);
8585
if (overwrite && tableExists)
8686
{
87-
if (modelDef.PreDropTableSql != null)
88-
{
89-
ExecuteSql(dbCmd, modelDef.PreDropTableSql);
90-
}
91-
9287
DropTable(dbCmd, modelDef);
9388

9489
var postDropTableSql = dialectProvider.ToPostDropTableStatement(modelDef);
@@ -97,11 +92,6 @@ internal static bool CreateTable(this IDbCommand dbCmd, bool overwrite, Type mod
9792
ExecuteSql(dbCmd, postDropTableSql);
9893
}
9994

100-
if (modelDef.PostDropTableSql != null)
101-
{
102-
ExecuteSql(dbCmd, modelDef.PostDropTableSql);
103-
}
104-
10595
tableExists = false;
10696
}
10797

tests/ServiceStack.OrmLite.Tests/CustomSqlTests.cs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,18 @@ public class ModelWithPostDropSql
8080
public string Name { get; set; }
8181
}
8282

83+
[PreDropTable("-- PreDropTable")]
84+
[PostDropTable("-- PostDropTable")]
85+
[PreCreateTable("-- PreCreateTable")]
86+
[PostCreateTable("-- PostCreateTable")]
87+
public class ModelWithPreAndPostDrop
88+
{
89+
[AutoIncrement]
90+
public int Id { get; set; }
91+
92+
public string Name { get; set; }
93+
}
94+
8395
[TestFixtureOrmLite]
8496
public class CustomSqlTests : OrmLiteProvidersTestBase
8597
{
@@ -165,6 +177,14 @@ public void Does_execute_CustomSql_after_table_created_using_dynamic_attribute()
165177
Assert.That(seedDataNames, Is.EquivalentTo(new[] {"Foo", "Bar"}));
166178
}
167179

180+
[Test]
181+
public void Does_execute_PostCreateTable_and_PreDropTable()
182+
{
183+
OrmLiteUtils.PrintSql();
184+
using var db = OpenDbConnection();
185+
db.CreateTable<ModelWithPreAndPostDrop>(true);
186+
}
187+
168188
[Test]
169189
public void Does_execute_CustomSql_before_table_dropped()
170190
{

0 commit comments

Comments
 (0)