public DownMigration(IDatabaseMetadataProvider databaseMetadataProvider, IVersionRespository versionRespository, IAppliedScriptsRepository appliedScriptsRepository, bool force) { _databaseMetadataProvider = databaseMetadataProvider; _versionRespository = versionRespository; _appliedScriptsRepository = appliedScriptsRepository; _force = force; }
protected override void Arrange() { var mess = $"Violation of PRIMARY KEY constraint 'BackwardsPkName_PK'. Cannot insert duplicate key in object 'edfi.Session'. The duplicate key value is (900007, 9, 2014). {Environment.NewLine}The statement has been terminated."; exception = NHibernateExceptionBuilder.CreateException("Generic exception message", mess); suppliedMetadataProvider = Stub <IDatabaseMetadataProvider>(); A.CallTo(() => suppliedMetadataProvider.GetIndexDetails("BackwardsPkName_PK")) .Returns(null); }
protected override void EstablishContext() { var mess = "Violation of PRIMARY KEY constraint 'BackwardsPkName_PK'. Cannot insert duplicate key in object 'edfi.Session'. The duplicate key value is (900007, 9, 2014). \r\nThe statement has been terminated."; exception = NHibernateExceptionBuilder.CreateException("Generic exception message", mess); suppliedMetadataProvider = mocks.StrictMock <IDatabaseMetadataProvider>(); SetupResult.For(suppliedMetadataProvider.GetIndexDetails("BackwardsPkName_PK")) .Return(null); }
internal static cs.CodeExpression TryBuildFromFragment(IDatabaseMetadataProvider databaseMetadata, TSqlFragment node, ref bool hasError, ref string error) { var vstor = new BooleanExpressionGeneratorVisitor(databaseMetadata, node); node.Accept(vstor); if (vstor.HasError()) { //Console.WriteLine(vstor.lastError); hasError = true; error = vstor.lastError; return(null); } //hasError = false; //error = null; return(vstor.BuildResult()); }
public static void InitializeTargetTable(IDatabaseMetadataProvider metadataProvider, ComboBox targetTableComboBox, string configurationTargetTable) { foreach (var table in metadataProvider.DatabaseTables) { ComboBoxItem comboBoxItem = new ComboBoxItem() { Content = table.TableName, ToolTip = table.TableName, Tag = table }; targetTableComboBox.Items.Add(comboBoxItem); if (configurationTargetTable == table.TableName) { targetTableComboBox.SelectedItem = comboBoxItem; } } targetTableComboBox.IsEnabled = true; }
/// <summary> /// Initialize a new dapper context /// </summary> public DBContext(IDatabaseMetadataProvider databaseMetadataProvider) { var connectionString = databaseMetadataProvider.GetConnectionString(); switch (databaseMetadataProvider.GetDbms()) { case Dbms.Mssql: QueryStrategy = new MicrosoftSqlServerQueryStrategy(); _getConnection = () => new SqlConnection(connectionString); break; case Dbms.Mysql: QueryStrategy = new MysqlQueryStrategy(); _getConnection = () => new MySqlConnection(connectionString); break; } }
void bgwConnectionChanged_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e) { this.metadataProvider = ((object[])e.Result)[0] as IDatabaseMetadataProvider; if (this.metadataProvider != null) { ConfigurationContent.Content = null; CommonDbInitializationHelper.InitializeTargetTable(this.metadataProvider, ddTargetTables, configuration.TargetTable); } Exception error = ((object[])e.Result)[0] as Exception; if (error != null) { string message = error.Message + ((error.InnerException != null) ? "\n" + error.InnerException.Message : ""); ConfigurationContent.Content = new MessageControl("An error occured:", message); } }
protected override void EstablishContext() { const string mess = "Violation of PRIMARY KEY constraint 'PK_Session'. Cannot insert duplicate key in object 'edfi.Session'. The duplicate key value is (900007, 9, 2014). \r\nThe statement has been terminated."; exception = NHibernateExceptionBuilder.CreateException("Generic SQL Exception message...", mess); suppliedMetadataProvider = mocks.StrictMock <IDatabaseMetadataProvider>(); SetupResult.For(suppliedMetadataProvider.GetIndexDetails("PK_Session")) .Return( new IndexDetails { IndexName = "SomeIndexName", TableName = "Session", ColumnNames = new List <string> { "Column1", "Column2", "Column3" } }); }
protected override void Arrange() { string mess = $"Violation of PRIMARY KEY constraint 'PK_Session'. Cannot insert duplicate key in object 'edfi.Session'. The duplicate key value is (900007, 9, 2014). {Environment.NewLine}The statement has been terminated."; exception = NHibernateExceptionBuilder.CreateException("Generic SQL Exception message...", mess); suppliedMetadataProvider = Stub <IDatabaseMetadataProvider>(); A.CallTo(() => suppliedMetadataProvider.GetIndexDetails("PK_Session")) .Returns( new IndexDetails { IndexName = "SomeIndexName", TableName = "Session", ColumnNames = new List <string> { "Column1", "Column2", "Column3" } }); }
protected override void Arrange() { _suppliedUpdateException = NHibernateExceptionBuilder.CreateException( "could not insert: [EdFi.Ods.Entities.AcademicHonorsTypeAggregate.AcademicHonorsType][SQL: INSERT INTO edfi.AcademicHonorsType (LastModifiedDate, CreateDate, Id, CodeValue, Description) VALUES (?, ?, ?, ?, ?); select SCOPE_IDENTITY()]", $"Cannot insert duplicate key row in object 'edfi.AcademicHonorsType' with unique index 'SomeIndexName'. The duplicate key value is (69).{Environment.NewLine}The statement has been terminated."); _suppliedMetadataProvider = A.Fake <IDatabaseMetadataProvider>(); A.CallTo(() => _suppliedMetadataProvider.GetIndexDetails("SomeIndexName")) .Returns( new IndexDetails { IndexName = "SomeIndexName", TableName = "SomeTableName", ColumnNames = new List <string> { "Column1" } }); }
public async void ConnectionChanged(IConnection connection) { this.connection = connection; ConfigurationContent.Content = new LoadingControl(); ddTargetTables.IsEnabled = false; try { await Task.Run(() => { metadataProvider = LoadMetadata(); }); ConfigurationContent.Content = null; CommonDbInitializationHelper.InitializeTargetTable(metadataProvider, ddTargetTables, configuration.TargetTable); ddTargetTables.IsEnabled = true; } catch (Exception ex) { ConfigurationContent.Content = new MessageControl("An error occured:", ex.ToString()); } }
private static void RunMigration(MigrationInfo migrationInfo, DatabaseVersion currentVersion, IEnumerable<Script> initScripts, IEnumerable<Script> upScripts, IEnumerable<Script> downScripts, IEnumerable<Script> termScripts, IList<IStep> storedSteps, IScriptRunner scriptRunner, IDatabaseMetadataProvider databaseMetadataProvider, IVersionRespository versionRespository, IAppliedScriptsRepository appliedScriptsRepository) { var upDownSteps = upScripts.Select(u => new DatabaseStep(u, downScripts.FirstOrDefault(d => d.Version == u.Version))).ToList(); var initTermSteps = initScripts.Select(i => new DatabaseStep(i, termScripts.FirstOrDefault(t => t.Version == i.Version))).ToList(); if (migrationInfo.Direction == MigrationDirection.Down) { var downMigration = new DownMigration(databaseMetadataProvider, versionRespository, appliedScriptsRepository, migrationInfo.Forced); if (storedSteps.Any()) { Output.Warn("NOTE: Using stored applied scripts to perform downgrade instead of local 'down' scripts."); downMigration.Migrate(storedSteps, currentVersion, migrationInfo.TargetVersion, scriptRunner, migrationInfo.TargetSchema, migrationInfo.TargetTablespace); } else { downMigration.Migrate(upDownSteps, currentVersion, migrationInfo.TargetVersion, scriptRunner, migrationInfo.TargetSchema, migrationInfo.TargetTablespace); } if (!migrationInfo.TargetVersion.HasValue) { var termMigration = new TermMigration(databaseMetadataProvider, migrationInfo.Forced); termMigration.Migrate(initTermSteps, currentVersion, migrationInfo.TargetVersion, scriptRunner, migrationInfo.TargetSchema, migrationInfo.TargetTablespace); } else { Output.Info("A target version was provided, termination scripts will not be executed."); } } else { var initMigration = new InitMigration(databaseMetadataProvider, migrationInfo.Forced); initMigration.Migrate(initTermSteps, currentVersion, migrationInfo.TargetVersion, scriptRunner, migrationInfo.TargetSchema, migrationInfo.TargetTablespace); EnsureVersioningTableIsInitialised(versionRespository, migrationInfo.TargetSchema, migrationInfo.TargetTablespace); EnsureAppliedScriptsTableIsInitialised(appliedScriptsRepository, migrationInfo.TargetSchema, migrationInfo.TargetTablespace); var upMigration = new UpMigration(versionRespository, appliedScriptsRepository, migrationInfo.Forced); upMigration.Migrate(upDownSteps, currentVersion, migrationInfo.TargetVersion, scriptRunner, migrationInfo.TargetSchema, migrationInfo.TargetTablespace); } }
public TermMigration(IDatabaseMetadataProvider databaseMetadataProvider, bool force) { _databaseMetadataProvider = databaseMetadataProvider; _force = force; }
public BooleanExpressionGeneratorVisitor(IDatabaseMetadataProvider databaseMetadata, TSqlFragment source) { this.databaseMetadata = databaseMetadata; this.source = source; }
public CommonConfiguration(IDatastore dataObject, IDatabaseMetadataProvider databaseMetadataProvider) { InitializeComponent(); }
public SqlServerUniqueIndexExceptionTranslator(IDatabaseMetadataProvider databaseMetadataProvider) { _databaseMetadataProvider = databaseMetadataProvider; }
public DuplicateNaturalKeyCreateExceptionTranslator(IDatabaseMetadataProvider databaseMetadataProvider) { _databaseMetadataProvider = databaseMetadataProvider; }
private static void RunMigration(MigrationInfo migrationInfo, DatabaseVersion currentVersion, IEnumerable <Script> initScripts, IEnumerable <Script> upScripts, IEnumerable <Script> downScripts, IEnumerable <Script> termScripts, IList <IStep> storedSteps, IScriptRunner scriptRunner, IDatabaseMetadataProvider databaseMetadataProvider, IVersionRespository versionRespository, IAppliedScriptsRepository appliedScriptsRepository) { var upDownSteps = upScripts.Select(u => new DatabaseStep(u, downScripts.FirstOrDefault(d => d.Version == u.Version))).ToList(); var initTermSteps = initScripts.Select(i => new DatabaseStep(i, termScripts.FirstOrDefault(t => t.Version == i.Version))).ToList(); if (migrationInfo.Direction == MigrationDirection.Down) { var downMigration = new DownMigration(databaseMetadataProvider, versionRespository, appliedScriptsRepository, migrationInfo.Forced); if (storedSteps.Any()) { Output.Warn("NOTE: Using stored applied scripts to perform downgrade instead of local 'down' scripts."); downMigration.Migrate(storedSteps, currentVersion, migrationInfo.TargetVersion, scriptRunner, migrationInfo.TargetSchema, migrationInfo.TargetTablespace); } else { downMigration.Migrate(upDownSteps, currentVersion, migrationInfo.TargetVersion, scriptRunner, migrationInfo.TargetSchema, migrationInfo.TargetTablespace); } if (!migrationInfo.TargetVersion.HasValue) { var termMigration = new TermMigration(databaseMetadataProvider, migrationInfo.Forced); termMigration.Migrate(initTermSteps, currentVersion, migrationInfo.TargetVersion, scriptRunner, migrationInfo.TargetSchema, migrationInfo.TargetTablespace); } else { Output.Info("A target version was provided, termination scripts will not be executed."); } } else { var initMigration = new InitMigration(databaseMetadataProvider, migrationInfo.Forced); initMigration.Migrate(initTermSteps, currentVersion, migrationInfo.TargetVersion, scriptRunner, migrationInfo.TargetSchema, migrationInfo.TargetTablespace); EnsureVersioningTableIsInitialised(versionRespository, migrationInfo.TargetSchema, migrationInfo.TargetTablespace); EnsureAppliedScriptsTableIsInitialised(appliedScriptsRepository, migrationInfo.TargetSchema, migrationInfo.TargetTablespace); var upMigration = new UpMigration(versionRespository, appliedScriptsRepository, migrationInfo.Forced); upMigration.Migrate(upDownSteps, currentVersion, migrationInfo.TargetVersion, scriptRunner, migrationInfo.TargetSchema, migrationInfo.TargetTablespace); } }