/// <summary> /// Creates the database. /// </summary> public void Create() { masterSqlConnection.Open(); try { master.ExecuteNonQuery("drop database [" + databaseName + "]"); } catch { } master.ExecuteNonQuery("create database [" + databaseName + "]"); sqlConnection.Open(); }
private void CreateColumn(AdHocSqlRunner sqlRunner) { var fullTableName = SqlTableJournal.CreateTableName(Schema, SqlTableJournal.Table); log().WriteInformation($"Adding Version column to the {fullTableName} table"); sqlRunner.ExecuteNonQuery($@"alter table {fullTableName} add [Version] varchar(100) null"); log().WriteInformation($"The Version columns was added to the {fullTableName} table"); }
/// <summary> /// Verifies the existence of targeted schema. If schema is not verified, will check for the existence of the dbo schema. /// </summary> public void VerifySchema() { if (string.IsNullOrEmpty(Schema)) { return; } var sqlRunner = new AdHocSqlRunner(connectionFactory, Schema, () => true); sqlRunner.ExecuteNonQuery(string.Format( @"IF NOT EXISTS (SELECT * FROM sys.schemas WHERE name = N'{0}') Exec('CREATE SCHEMA {0}')", Schema)); }
/// <summary> /// Verifies the existence of targeted schema. If schema is not verified, will check for the existence of the dbo schema. /// </summary> public void VerifySchema() { if (string.IsNullOrEmpty(Schema)) return; connectionManagerFactory().ExecuteCommandsWithManagedConnection(dbCommandFactory => { var sqlRunner = new AdHocSqlRunner(dbCommandFactory, Schema, () => true); sqlRunner.ExecuteNonQuery(string.Format( @"IF NOT EXISTS (SELECT * FROM sys.schemas WHERE name = N'{0}') Exec('CREATE SCHEMA [{0}]')", Schema)); }); }
/// <summary> /// Verifies the existence of targeted schema. If schema is not verified, will check for the existence of the dbo schema. /// </summary> public void VerifySchema() { if (string.IsNullOrEmpty(Schema)) { return; } connectionManagerFactory().ExecuteCommandsWithManagedConnection(dbCommandFactory => { var sqlRunner = new AdHocSqlRunner(dbCommandFactory, sqlObjectParser, Schema, () => true); var sql = GetVerifySchemaSql(Schema); sqlRunner.ExecuteNonQuery(sql); }); }
private void CreateTable(AdHocSqlRunner sqlRunner) { var fullTableName = SqlTableJournal.CreateTableName(Schema, SqlTableJournal.Table); var primaryKeyConstraintName = CreatePrimaryKeyName(SqlTableJournal.Table); log().WriteInformation($"Creating the {fullTableName} table"); sqlRunner.ExecuteNonQuery($@"create table {fullTableName} ( [Id] int identity(1,1) not null constraint {primaryKeyConstraintName} primary key, [ScriptName] nvarchar(255) not null, [Applied] datetime not null, [Version] varchar(100) not null )"); log().WriteInformation($"The {fullTableName} table has been created"); }