Esempio n. 1
0
        public void Do1_1_RelationChange_FromNotNullable_To_Nullable(Relation rel, RelationEndRole role)
        {
            RelationEnd relEnd = rel.GetEndFromRole(role);
            RelationEnd otherEnd = rel.GetOtherEndFromRole(role);

            var tblName = db.GetTableName(relEnd.Type.Module.SchemaName, relEnd.Type.TableName);
            var colName = Construct.ForeignKeyColumnName(otherEnd);

            if (db.CheckColumnContainsNulls(tblName, colName))
            {
                Log.ErrorFormat("column '{0}.{1}' contains NULL values, cannot set NOT NULLABLE", tblName, colName);
            }
            else
            {
                db.AlterColumn(tblName, colName, System.Data.DbType.Int32, 0, 0, otherEnd.IsNullable(), null);
            }
        }
Esempio n. 2
0
        public void Do1_1_RelationChange_FromNullable_To_NotNullable(Relation rel, RelationEndRole role)
        {
            RelationEnd relEnd = rel.GetEndFromRole(role);
            RelationEnd otherEnd = rel.GetOtherEndFromRole(role);

            var tblName = db.GetTableName(relEnd.Type.Module.SchemaName, relEnd.Type.TableName);
            var colName = Construct.ForeignKeyColumnName(otherEnd);

            db.AlterColumn(tblName, colName, System.Data.DbType.Int32, 0, 0, otherEnd.IsNullable(), null);
        }
Esempio n. 3
0
 public bool Is1_1_RelationChange_FromNullable_To_NotNullable(Relation rel, RelationEndRole role)
 {
     Relation savedRel = savedSchema.FindPersistenceObject<Relation>(rel.ExportGuid);
     if (savedRel == null)
     {
         return false;
     }
     return savedRel.GetOtherEndFromRole(role).IsNullable() && !rel.GetOtherEndFromRole(role).IsNullable()
         && ((rel.Storage == StorageType.MergeIntoA && role == RelationEndRole.A)
             || (rel.Storage == StorageType.MergeIntoB && role == RelationEndRole.B)
             || (rel.Storage == StorageType.Replicate));
 }
Esempio n. 4
0
        public void Do_1_1_RelationChange_FromNullable_To_NotNullable(Relation rel, RelationEndRole role)
        {
            var savedRel = savedSchema.FindPersistenceObject<Relation>(rel.ExportGuid);

            if (!PreMigration(RelationMigrationEventType.ChangeToNotNullable, savedRel, rel))
                return;

            RelationEnd relEnd = rel.GetEndFromRole(role);
            RelationEnd otherEnd = rel.GetOtherEndFromRole(role);

            var tblName = relEnd.Type.GetTableRef(db);
            var colName = Construct.ForeignKeyColumnName(otherEnd);
            var idxName = Construct.IndexName(tblName.Name, colName);

            // MS SQL Server (and Postgres?) cannot alter columns when a index exists
            if (db.CheckIndexExists(tblName, idxName)) db.DropIndex(tblName, idxName);
            db.AlterColumn(tblName, colName, System.Data.DbType.Int32, 0, 0, otherEnd.IsNullable(), null);
            db.CreateIndex(tblName, idxName, false, false, colName);

            PostMigration(RelationMigrationEventType.ChangeToNotNullable, savedRel, rel);
        }