public virtual void WriteStructureBeforeData(IDatabaseStructure db) { // create tables without foreign keys DatabaseStructure dbcopy = new DatabaseStructure(db); foreach (TableStructure tbl in dbcopy.Tables) { tbl.RemoveConstraints <IForeignKey>(); } m_dmp.CreateDatabaseObjects(dbcopy, new CreateDatabaseObjectsProps { CreateSpecificObjects = false }); }
public void CreateAllObjects(IDatabaseSource conn, ISqlDumper dmp, ISqlDialect dialect) { var dbmem = new DatabaseStructureMembers { TableList = true, TableMembers = TableStructureMembers.AllNoRefs, DomainList = true, DomainDetails = true, SpecificObjectList = true, SpecificObjectDetails = true, LoadDependencies = true, IgnoreSystemObjects = true, }; var dbs = new DatabaseStructure(conn.InvokeLoadStructure(dbmem, null)); var props = new CreateDatabaseObjectsProps { CreateDomains = Domains, CreateFixedData = FixedData, CreateSchemata = Schemata, CreateSpecificObjects = SpecificObjects, CreateTables = Tables }; IMigrationProfile profile = dialect.CreateMigrationProfile(); dialect.MigrateDatabase(dbs, profile, null); dmp.CreateDatabaseObjects(dbs, props); }
public void GetAlterSql(ISqlDumper dmp) { VersionDef current = Version; VersionDef prev = Version.GetVersion(-1); var vardef = new VariantDef(VariantFile); DatabaseStructure curstruct = current.LoadStructure(vardef); DatabaseStructure prevstruct = prev.LoadStructure(vardef); ISqlDialect dialect = curstruct.Dialect ?? Version.Db.Dialect; DbDiffOptions opts = new DbDiffOptions(); //if (prev != null) dmp.TargetDb = new DbDefSource(DatabaseStructure.Load(prev.GetFile()), DbDefSource.ReadOnly.Flag); opts.AllowRecreateTable = true; if (prevstruct == null) { dmp.CreateDatabaseObjects(curstruct); } else { dmp.AlterDatabase(prevstruct, curstruct, opts, new Plugin.dbmodel.DbDefSource(prevstruct, Plugin.dbmodel.DbDefSource.ReadOnly.Flag), null); } current.SetVersionSql(dmp); }
public void GetAlterSql(ISqlDumper dmp) { DumpSubFolder(dmp, "before"); VersionDef current = this; VersionDef prev = current.GetVersion(-1); VersionDb vdb = current.Db; DatabaseStructure curstruct = DatabaseStructure.Load(current.GetFile()); DatabaseStructure prevstruct = null; if (prev != null) { prevstruct = DatabaseStructure.Load(prev.GetFile()); } ISqlDialect dialect = vdb.Dialect; DbDiffOptions opts = new DbDiffOptions(); //if (prev != null) dmp.TargetDb = new DbDefSource(DatabaseStructure.Load(prev.GetFile()), DbDefSource.ReadOnly.Flag); opts.AllowRecreateTable = true; if (prevstruct == null) { dmp.CreateDatabaseObjects(curstruct); } else { dmp.AlterDatabase(prevstruct, curstruct, opts, new Plugin.dbmodel.DbDefSource(prevstruct, Plugin.dbmodel.DbDefSource.ReadOnly.Flag), AddSubFoldersToPlan); } DumpSubFolder(dmp, "after"); current.SetVersionSql(dmp); }
public void CreateSpecificObjects(ISqlDumper dmp, IDatabaseStructure db) { dmp.CreateDatabaseObjects(db, new CreateDatabaseObjectsProps { AllFlags = false, CreateSpecificObjects = true, }); }
public void CreateTables(ISqlDumper dmp, IDatabaseStructure db) { // create tables without foreign keys DatabaseStructure dbcopy = new DatabaseStructure(db); foreach (TableStructure tbl in dbcopy.Tables) { RemoveUnwantedTableFeature(tbl); } dmp.CreateDatabaseObjects(dbcopy, new CreateDatabaseObjectsProps { AllFlags = false, CreateTables = true, }); }
public override void GenerateSql(AppObject appobj, ISqlDumper dmp, ISqlDialect dialect) { var vdb = (VersionDbAppObject)appobj; var fromv = vdb.GetVdb().FindVersion(FromVersion); var tov = vdb.GetVdb().FindVersion(ToVersion); DatabaseStructure fromstruct = null; if (fromv != null) { fromstruct = DatabaseStructure.Load(fromv.GetFile()); } DatabaseStructure tostruct = null; if (tov != null) { tostruct = DatabaseStructure.Load(tov.GetFile()); } if (tostruct == null) { return; } DbDiffOptions opts = new DbDiffOptions(); //if (prev != null) dmp.TargetDb = new DbDefSource(DatabaseStructure.Load(prev.GetFile()), DbDefSource.ReadOnly.Flag); opts.AllowRecreateTable = true; if (fromstruct == null) { dmp.CreateDatabaseObjects(tostruct); } else { dmp.AlterDatabase(fromstruct, tostruct, opts, new Plugin.dbmodel.DbDefSource(fromstruct, Plugin.dbmodel.DbDefSource.ReadOnly.Flag), null); } tov.SetVersionSql(dmp); }
public static void CreateDatabaseObjects(this ISqlDumper dmp, IDatabaseStructure db) { dmp.CreateDatabaseObjects(db, new CreateDatabaseObjectsProps()); }