public void SetVersion(MigratorDatabase migratorDatabase, long version) { if (migratorDatabase.ExecuteSqlCommand($"UPDATE {TableName} SET {DatabaseVersionColumnName} = {version}") == 0) { migratorDatabase.ExecuteSqlCommand($"INSERT INTO {TableName}(Version) VALUES({version})"); } }
private void Create(MigratorDatabase migratorDatabase) { if (HasSchema) { CreateSchemaIfNotExisting(migratorDatabase); } try { migratorDatabase.ExecuteSqlCommand($@" CREATE TABLE {TableName} ( Id UNIQUEIDENTIFIER DEFAULT NEWID() PRIMARY KEY CLUSTERED, [Version] BIGINT )"); } catch (SqlException e) when(e.Number == ThereIsAlreadyAnObjectNamedXXXXInTheDatabase) { } }
private void CreateSchemaIfNotExisting(MigratorDatabase migratorDatabase) { var schemaCount = migratorDatabase.SqlQuery <int>($@" SELECT Count(schema_name) FROM information_schema.schemata WHERE schema_name = '{SchemaName}'").Single(); if (schemaCount == 1) { return; } try { migratorDatabase.ExecuteSqlCommand($"CREATE SCHEMA {SchemaName}"); } catch (SqlException e) when(e.Number == ThereIsAlreadyAnObjectNamedXXXXInTheDatabase) { } }