예제 #1
0
        protected void PerformFullTableCheck(IManageable model, string connectionToUse)
        {
            if (model.IsFullyValidated)
            {
                Logger.Info($"Table {model.Configuration.TableName} has already been validated with it's current state.");
                return;
            }

            Logger.Info($"Processing table {model.Configuration.TableName} using connection {connectionToUse}.");
            model.IsFullyValidated = true;
            string schema         = Manager.ConnectionType == ConnectionTypes.MSSQL ? model.Configuration.Schema : ConsolidationTools.GetInitialCatalog(connectionToUse, true);
            string initialCatalog = ConsolidationTools.GetInitialCatalog(connectionToUse);
            Dictionary <string, ConstraintDefinition> constraints = GetConstraints(initialCatalog, schema, model.Configuration.TableName, connectionToUse);

            if (DoTableExist(initialCatalog, schema, model.Configuration.TableName, connectionToUse))
            {
                ExecuteScalar(_creator.CreateQueryForTableAlteration(model, GetColumnDefinition(initialCatalog, model.Configuration.Schema, model.Configuration.TableName, connectionToUse), constraints), connectionToUse, false);
            }
            else
            {
                ExecuteScalar(_creator.CreateQueryForTableCreation(model), connectionToUse, false);
            }

            VerifyForeignTables(model, connectionToUse);
            string foreignKeyQuery = _creator.GetCreateForeignKeysQuery(model, constraints);

            if (!string.IsNullOrWhiteSpace(foreignKeyQuery))
            {
                ExecuteScalar(foreignKeyQuery, connectionToUse, false);
            }
        }