Example #1
0
        public static bool InitDB(this IDatabase database)
        {
            try
            {
                DatabaseFixes.InitFixes();
                if (!database.DatabaseAlreadyExists())
                {
                    database.CreateDatabase();
                    Thread.Sleep(3000);
                }
                Thread.CurrentThread.CurrentUICulture = CultureInfo.GetCultureInfo(ServerSettings.Culture);

                JMMService.CloseSessionFactory();
                ServerState.Instance.CurrentSetupStatus = JMMServer.Properties.Resources.Database_Initializing;
                ISessionFactory temp = JMMService.SessionFactory;
                ServerState.Instance.CurrentSetupStatus = JMMServer.Properties.Resources.Database_CreateSchema;
                bool res = database.CreateInitialSchema();
                if (!res)
                {
                    int version = database.GetDatabaseVersion();
                    if (version > database.RequiredVersion)
                    {
                        ServerState.Instance.CurrentSetupStatus = JMMServer.Properties.Resources.Database_NotSupportedVersion;
                        return(false);
                    }
                    if (version < database.RequiredVersion)
                    {
                        ServerState.Instance.CurrentSetupStatus = JMMServer.Properties.Resources.Database_Backup;
                        database.BackupDatabase(GetDatabaseBackupName(version));
                    }
                }
                ServerState.Instance.CurrentSetupStatus = JMMServer.Properties.Resources.Database_ApplySchema;
                database.UpdateSchema();
                RepoFactory.Init();
                DatabaseFixes.ExecuteDatabaseFixes();
                database.PopulateInitialData();

                return(true);
            }
            catch (Exception ex)
            {
                logger.Error(ex, "Could not init database: " + ex.ToString());
                ServerState.Instance.CurrentSetupStatus = JMMServer.Properties.Resources.Server_DatabaseFail;
                return(false);
            }
        }
Example #2
0
        public static bool InitDB()
        {
            try
            {
                if (ServerSettings.DatabaseType.Trim().ToUpper() == "SQLSERVER")
                {
                    if (!SQLServer.DatabaseAlreadyExists())
                    {
                        logger.Error("Database: {0} does not exist", ServerSettings.DatabaseName);
                        SQLServer.CreateDatabase();
                        Thread.Sleep(3000);
                    }

                    JMMService.CloseSessionFactory();
                    ServerState.Instance.CurrentSetupStatus = JMMServer.Properties.Resources.Database_Initializing;
                    ISessionFactory temp = JMMService.SessionFactory;

                    ServerState.Instance.CurrentSetupStatus = JMMServer.Properties.Resources.Database_CreateSchema;
                    SQLServer.CreateInitialSchema();

                    ServerState.Instance.CurrentSetupStatus = JMMServer.Properties.Resources.Database_ApplySchema;
                    SQLServer.UpdateSchema();

                    PopulateInitialData();
                    DatabaseHelper.CreateInitialCustomTags();

                    return(true);
                }
                else if (ServerSettings.DatabaseType.Trim().ToUpper() == "SQLITE")
                {
                    ServerState.Instance.CurrentSetupStatus = JMMServer.Properties.Resources.Database_CreateDatabase;
                    SQLite.CreateDatabase();

                    JMMService.CloseSessionFactory();
                    ServerState.Instance.CurrentSetupStatus = JMMServer.Properties.Resources.Database_Initializing;
                    ISessionFactory temp = JMMService.SessionFactory;

                    ServerState.Instance.CurrentSetupStatus = JMMServer.Properties.Resources.Database_CreateSchema;
                    SQLite.CreateInitialSchema();

                    ServerState.Instance.CurrentSetupStatus = JMMServer.Properties.Resources.Database_ApplySchema;
                    SQLite.UpdateSchema();

                    PopulateInitialData();
                    DatabaseHelper.CreateInitialCustomTags();

                    return(true);
                }
                else if (ServerSettings.DatabaseType.Trim().ToUpper() == "MYSQL")
                {
                    logger.Trace("Database - Creating Database...");
                    ServerState.Instance.CurrentSetupStatus = JMMServer.Properties.Resources.Database_CreateDatabase;
                    MySQL.CreateDatabase();

                    logger.Trace("Initializing Session Factory...");
                    JMMService.CloseSessionFactory();
                    ServerState.Instance.CurrentSetupStatus = JMMServer.Properties.Resources.Database_Initializing;
                    ISessionFactory temp = JMMService.SessionFactory;

                    logger.Trace("Database - Creating Initial Schema...");
                    ServerState.Instance.CurrentSetupStatus = JMMServer.Properties.Resources.Database_CreateSchema;
                    MySQL.CreateInitialSchema();

                    logger.Trace("Database - Applying Schema Patches...");
                    ServerState.Instance.CurrentSetupStatus = JMMServer.Properties.Resources.Database_ApplySchema;
                    MySQL.UpdateSchema();
                    //MySQL.UpdateSchema_Fix();

                    PopulateInitialData();
                    DatabaseHelper.CreateInitialCustomTags();

                    return(true);
                }

                return(false);
            }
            catch (Exception ex)
            {
                logger.ErrorException("Could not init database: " + ex.ToString(), ex);
                return(false);
            }
        }