Example #1
0
        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);
        }
Example #2
0
        public virtual void CreateDatabaseObjects(IDatabaseStructure db, CreateDatabaseObjectsProps props)
        {
            if (Dialect.DialectCaps.Domains && props.CreateDomains)
            {
                foreach (var domain in db.Domains)
                {
                    try
                    {
                        CreateDomain(domain);
                    }
                    catch (Exception err)
                    {
                        ProgressInfo.RaiseErrorEx(err, "DAE-00244 " + Texts.Get("s_error_creating$domain", "domain", domain.FullName), "DOMAIN");
                    }
                }
            }
            if (Dialect.DialectCaps.MultipleSchema && props.CreateSchemata)
            {
                foreach (var schema in db.Schemata)
                {
                    try
                    {
                        CreateSchema(schema);
                    }
                    catch (Exception err)
                    {
                        ProgressInfo.RaiseErrorEx(err, "DAE-00245 " + Texts.Get("s_error_creating$schema", "schema", schema.SchemaName), "SCHEMA");
                    }
                }
            }
            var refsToCreate = new List <IForeignKey>();

            if (props.CreateTables)
            {
                foreach (var tbl in db.Tables)
                {
                    ITableStructure tbl2 = tbl;
                    if (!Dialect.DialectCaps.UncheckedReferences)
                    {
                        var newtbl = new TableStructure(tbl);
                        foreach (ForeignKey fk in new List <ForeignKey>(newtbl.GetConstraints <ForeignKey>()))
                        {
                            newtbl._Constraints.Remove(fk);
                            fk.SetDummyTable(tbl.FullName);
                            refsToCreate.Add(fk);
                        }
                        tbl2 = newtbl;
                    }

                    Logging.Debug("Creating table {0}", tbl2.FullName);
                    SetCurWork(String.Format("{0} {1}", Texts.Get("s_creating_table"), tbl2.FullName));
                    if (m_props.DumpWriterConfig != null && m_props.DumpWriterConfig.IncludeDropStatement)
                    {
                        DropTable(tbl2, DropFlags.TestIfExist);
                    }
                    try
                    {
                        CreateTable(tbl2);
                    }
                    catch (Exception err)
                    {
                        ProgressInfo.RaiseErrorEx(err, "DAE-00246 " + Texts.Get("s_error_creating$table", "table", tbl2.FullName), "TABLE");
                    }
                }
            }
            if (props.CreateFixedData)
            {
                foreach (var tbl in db.Tables)
                {
                    this.UpdateData(tbl, DbDiffTool.AlterFixedData(null, tbl.FixedData, null, new DbDiffOptions()), null);
                }
            }
            foreach (var fk in refsToCreate)
            {
                CreateConstraint(fk);
            }
            if (props.CreateSpecificObjects)
            {
                foreach (var obj in db.GetSpecObjectsOrderByDependency())
                {
                    SetCurWork(String.Format("{0} {1}", Texts.Get("s_creating_object"), obj.ObjectName));
                    if (m_props.DumpWriterConfig != null && m_props.DumpWriterConfig.IncludeDropStatement)
                    {
                        DropSpecificObject(obj, DropFlags.TestIfExist);
                    }
                    try
                    {
                        CreateSpecificObject(obj);
                    }
                    catch (Exception err)
                    {
                        if (ProgressInfo != null)
                        {
                            ProgressInfo.LogMessage("s_create_object", LogLevel.Error, Texts.Get("s_error_creating_object$name", "name", obj.ObjectName) + ": " + err.Message);
                        }
                        Logging.Error("Error creating object:" + err.ToString());
                    }
                }
            }
        }