From 768e95b958902afacda1e09ecc8f98bdce20c340 Mon Sep 17 00:00:00 2001 From: Joe Nathan Abellard Date: Sun, 9 Jul 2023 12:20:53 -0400 Subject: [PATCH] Set default table creation style to CreationStyle.CreateIfNotExists --- src/Weasel.Core/Migrator.cs | 2 +- src/Weasel.Postgresql.Tests/DdlRulesTester.cs | 4 ++-- src/Weasel.Postgresql.Tests/Tables/TableTests.cs | 5 ++--- src/Weasel.SqlServer.Tests/DdlRulesTester.cs | 4 ++-- src/Weasel.SqlServer.Tests/Tables/TableTests.cs | 5 ++--- 5 files changed, 9 insertions(+), 11 deletions(-) diff --git a/src/Weasel.Core/Migrator.cs b/src/Weasel.Core/Migrator.cs index 39c20f0a..e9666088 100644 --- a/src/Weasel.Core/Migrator.cs +++ b/src/Weasel.Core/Migrator.cs @@ -35,7 +35,7 @@ protected Migrator(string defaultSchemaName) /// /// Alters the syntax used to create tables in DDL /// - public CreationStyle TableCreation { get; set; } = CreationStyle.DropThenCreate; + public CreationStyle TableCreation { get; set; } = CreationStyle.CreateIfNotExists; /// /// Alters the user rights for the upsert functions in DDL diff --git a/src/Weasel.Postgresql.Tests/DdlRulesTester.cs b/src/Weasel.Postgresql.Tests/DdlRulesTester.cs index b2ce3375..ddfa24dc 100644 --- a/src/Weasel.Postgresql.Tests/DdlRulesTester.cs +++ b/src/Weasel.Postgresql.Tests/DdlRulesTester.cs @@ -19,9 +19,9 @@ public void role_is_null_by_default() } [Fact] - public void table_creation_is_drop_then_create_by_default() + public void table_creation_is_create_if_not_exists_by_default() { - new PostgresqlMigrator().TableCreation.ShouldBe(CreationStyle.DropThenCreate); + new PostgresqlMigrator().TableCreation.ShouldBe(CreationStyle.CreateIfNotExists); } [Fact] diff --git a/src/Weasel.Postgresql.Tests/Tables/TableTests.cs b/src/Weasel.Postgresql.Tests/Tables/TableTests.cs index 79011875..a91fef71 100644 --- a/src/Weasel.Postgresql.Tests/Tables/TableTests.cs +++ b/src/Weasel.Postgresql.Tests/Tables/TableTests.cs @@ -107,7 +107,7 @@ public void smoke_test_writing_table_code_with_columns() table.AddColumn("first_name"); table.AddColumn("last_name"); - var rules = new PostgresqlMigrator { TableCreation = CreationStyle.DropThenCreate }; + var rules = new PostgresqlMigrator { TableCreation = CreationStyle.CreateIfNotExists }; var writer = new StringWriter(); table.WriteCreateStatement(rules, writer); @@ -118,8 +118,7 @@ public void smoke_test_writing_table_code_with_columns() var lines = ddl.ReadLines().ToArray(); - lines.ShouldContain("DROP TABLE IF EXISTS public.people CASCADE;"); - lines.ShouldContain("CREATE TABLE public.people ("); + lines.ShouldContain("CREATE TABLE IF NOT EXISTS public.people ("); } [Fact] diff --git a/src/Weasel.SqlServer.Tests/DdlRulesTester.cs b/src/Weasel.SqlServer.Tests/DdlRulesTester.cs index 44cef2e8..5e262e25 100644 --- a/src/Weasel.SqlServer.Tests/DdlRulesTester.cs +++ b/src/Weasel.SqlServer.Tests/DdlRulesTester.cs @@ -19,9 +19,9 @@ public void role_is_null_by_default() } [Fact] - public void table_creation_is_drop_then_create_by_default() + public void table_creation_is_create_if_not_exists_by_default() { - new SqlServerMigrator().TableCreation.ShouldBe(CreationStyle.DropThenCreate); + new SqlServerMigrator().TableCreation.ShouldBe(CreationStyle.CreateIfNotExists); } [Fact] diff --git a/src/Weasel.SqlServer.Tests/Tables/TableTests.cs b/src/Weasel.SqlServer.Tests/Tables/TableTests.cs index 0c0f6cb8..f60b34e7 100644 --- a/src/Weasel.SqlServer.Tests/Tables/TableTests.cs +++ b/src/Weasel.SqlServer.Tests/Tables/TableTests.cs @@ -99,7 +99,7 @@ public void smoke_test_writing_table_code_with_columns() table.AddColumn("first_name"); table.AddColumn("last_name"); - var rules = new SqlServerMigrator { TableCreation = CreationStyle.DropThenCreate }; + var rules = new SqlServerMigrator { TableCreation = CreationStyle.CreateIfNotExists }; var writer = new StringWriter(); table.WriteCreateStatement(rules, writer); @@ -110,8 +110,7 @@ public void smoke_test_writing_table_code_with_columns() var lines = ddl.ReadLines().ToArray(); - lines.ShouldContain("DROP TABLE IF EXISTS dbo.people;"); - lines.ShouldContain("CREATE TABLE dbo.people ("); + lines.ShouldContain("CREATE TABLE IF NOT EXISTS dbo.people ("); } [Fact]