コード例 #1
0
        private void Initialize()
        {
            if (!CanInitialize())
            {
                return;
            }

            GetCurrentSchemaVersion();

            _logger.LogInformation("Schema version is {version}", _schemaInformation.Current?.ToString() ?? "NULL");

            // GetCurrentVersion doesn't exist, so run version 1.
            if (_schemaInformation.Current == null || _sqlServerDataStoreConfiguration.DeleteAllDataOnStartup)
            {
                _schemaUpgradeRunner.ApplySchema(1);
                GetCurrentSchemaVersion();
            }

            if (_schemaInformation.Current < _schemaInformation.MaximumSupportedVersion)
            {
                int current = (int?)_schemaInformation.Current ?? 0;

                for (int i = current + 1; i <= (int)_schemaInformation.MaximumSupportedVersion; i++)
                {
                    _schemaUpgradeRunner.ApplySchema(i);
                }
            }
        }
コード例 #2
0
        internal void Initialize(bool forceIncrementalSchemaUpgrade = false)
        {
            if (!CanInitialize())
            {
                return;
            }

            GetCurrentSchemaVersion();

            _logger.LogInformation("Schema version is {version}", _schemaInformation.Current?.ToString() ?? "NULL");

            // If the stored procedure to get the current schema version doesn't exist
            if (_schemaInformation.Current == null || _sqlServerDataStoreConfiguration.DeleteAllDataOnStartup)
            {
                if (forceIncrementalSchemaUpgrade)
                {
                    // Run version 1. We'll use this as a base schema and apply .diff.sql files to upgrade the schema version.
                    _schemaUpgradeRunner.ApplySchema(version: 1, applyFullSchemaSnapshot: true);
                }
                else
                {
                    // Apply the maximum supported version. This won't consider the .diff.sql files.
                    _schemaUpgradeRunner.ApplySchema((int)_schemaInformation.MaximumSupportedVersion, applyFullSchemaSnapshot: true);
                }

                GetCurrentSchemaVersion();
            }

            // If the current schema version needs to be upgraded
            if (_schemaInformation.Current < _schemaInformation.MaximumSupportedVersion)
            {
                // Apply each .diff.sql file one by one.
                int current = (int?)_schemaInformation.Current ?? 0;
                for (int i = current + 1; i <= (int)_schemaInformation.MaximumSupportedVersion; i++)
                {
                    _schemaUpgradeRunner.ApplySchema(version: i, applyFullSchemaSnapshot: false);
                }
            }

            GetCurrentSchemaVersion();
        }