Skip to content

Set default table creation style to CreationStyle.CreateIfNotExists #92

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/Weasel.Core/Migrator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ protected Migrator(string defaultSchemaName)
/// <summary>
/// Alters the syntax used to create tables in DDL
/// </summary>
public CreationStyle TableCreation { get; set; } = CreationStyle.DropThenCreate;
public CreationStyle TableCreation { get; set; } = CreationStyle.CreateIfNotExists;

/// <summary>
/// Alters the user rights for the upsert functions in DDL
Expand Down
4 changes: 2 additions & 2 deletions src/Weasel.Postgresql.Tests/DdlRulesTester.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
5 changes: 2 additions & 3 deletions src/Weasel.Postgresql.Tests/Tables/TableTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ public void smoke_test_writing_table_code_with_columns()
table.AddColumn<string>("first_name");
table.AddColumn<string>("last_name");

var rules = new PostgresqlMigrator { TableCreation = CreationStyle.DropThenCreate };
var rules = new PostgresqlMigrator { TableCreation = CreationStyle.CreateIfNotExists };

var writer = new StringWriter();
table.WriteCreateStatement(rules, writer);
Expand All @@ -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]
Expand Down
4 changes: 2 additions & 2 deletions src/Weasel.SqlServer.Tests/DdlRulesTester.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
5 changes: 2 additions & 3 deletions src/Weasel.SqlServer.Tests/Tables/TableTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ public void smoke_test_writing_table_code_with_columns()
table.AddColumn<string>("first_name");
table.AddColumn<string>("last_name");

var rules = new SqlServerMigrator { TableCreation = CreationStyle.DropThenCreate };
var rules = new SqlServerMigrator { TableCreation = CreationStyle.CreateIfNotExists };

var writer = new StringWriter();
table.WriteCreateStatement(rules, writer);
Expand All @@ -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]
Expand Down