/// <summary>
        /// Replace elements by conventions<br/>
        /// Replace {SchemaName} with <paramref name="schemaName"/> or <see cref="IDbConfigSchemaTargets.Schema"/><br/>
        /// Replace {SchemaPrefixId} with <paramref name="schemaPrefixId"/> or  <see cref="IDbConfigSchemaTargets.GetSchemaPrefixId()"/><br/>
        /// Replace {SchemaPrefixUniqueId} with <paramref name="schemaPrefixUniqueId"/> or  <see cref="IDbMigrationConfig.GetSchemaPrefixUniqueId()"/><br/>
        /// Replace {MigrationName} with <paramref name="migrationName"/> or  <see cref="IDbMigrationConfig.GetMigrationName()"/><br/>
        /// Replace {SchemaPassword} with <paramref name="schemaPassword"/> or <see cref="IDbMigrationConfig.SchemaPassword"/> or <see cref="IDbConfigCredentials.Password"/> <br/>
        /// Replace {User} with <paramref name="user"/> or <see cref="IDbConfigCredentials.User"/><br/>
        /// Replace {Password} with <paramref name="password"/> or <see cref="IDbConfigCredentials.Password"/> or <see cref="IDbConfigCredentials.User"/> <br/>
        /// </summary>
        /// <param name="migrationConfig"></param>
        /// <param name="sql"></param>
        /// <param name="schemaName"></param>
        /// <param name="schemaPrefixId"></param>
        /// <param name="schemaPrefixUniqueId"></param>
        /// <param name="migrationName"></param>
        /// <param name="schemaPassword"></param>
        /// <param name="user"></param>
        /// <param name="password"></param>
        /// <returns></returns>
        public static string PrepareSql(this IDbMigrationConfig migrationConfig, string sql, string schemaName = null, string schemaPrefixId = null, string schemaPrefixUniqueId = null,
                                        string migrationName = null, string schemaPassword = null, string user = null, string password = null)
        {
            if (sql == null)
            {
                return(null);
            }

            schemaName           = schemaName ?? migrationConfig.Schema;
            schemaPassword       = schemaPassword ?? migrationConfig.SchemaPassword.WithDefault(schemaName).WithDefault(migrationConfig.GetDbConfig()?.Password);
            schemaPrefixId       = schemaPrefixId ?? migrationConfig.GetSchemaPrefixId();
            schemaPrefixUniqueId = schemaPrefixUniqueId ?? migrationConfig.GetSchemaPrefixUniqueId();
            migrationName        = migrationName ?? migrationConfig.GetMigrationName();

            user     = user ?? migrationConfig?.GetDbConfig().User.WithDefault(migrationName);
            password = password ?? migrationConfig?.GetDbConfig().Password;

            return(sql
                   .ReplaceIgnoreCase("{MigrationName}", migrationName)
                   .ReplaceIgnoreCase("{User}", user)
                   .ReplaceIgnoreCase("{Password}", password)
                   .ReplaceIgnoreCase("{SchemaName}", schemaName?.ToUpper())
                   .ReplaceIgnoreCase("{SchemaPassword}", schemaPassword?.ToUpper())
                   .ReplaceIgnoreCase("{SchemaPrefixId}", schemaPrefixId)
                   .ReplaceIgnoreCase("{SchemaPrefixUniqueId}", schemaPrefixUniqueId));
        }
        /// <summary>
        /// Resolve table-value by <paramref name="template"/> and <paramref name="tableName"/><br/>
        /// i.e: With <paramref name="template"/> equal to "tables:{<paramref name="tableName"/>}:globalId" and <paramref name="tableName"/> equal to "Person" (and ie. <paramref name="migrationConfig"/>.GetSchemaPrefixId() (<see cref="IDbConfigSchemaTargets.GetSchemaPrefixId()"/>) returns "EX" <br/>
        /// => Will search configuration:<br/>
        /// - "database:migration:tables:Person:globalId"<br/>
        /// - "database:migration:tables:EXPerson:globalId"<br/>
        /// - "database:tables:Person:globalId"<br/>
        /// - "database:tables:EXPerson:globalId"<br/>
        /// </summary>
        /// <param name="migrationConfig"></param>
        /// <param name="template">string template containing {tableName}</param>
        /// <param name="tableName"></param>
        /// <param name="fallbackTemplates"></param>
        /// <returns></returns>
        public static string GetTableConfigValue(this IDbMigrationConfig migrationConfig, string template, string tableName, params string[] fallbackTemplates)
        {
            if (migrationConfig == null)
            {
                return(null);
            }
            var defaultKey      = template.ReplaceIgnoreCase("{tableName}", tableName);
            var alternativeKey  = template.ReplaceIgnoreCase("{tableName}", tableName.TrimPrefixName(migrationConfig.GetSchemaPrefixId()));
            var alternativeKey2 = template.ReplaceIgnoreCase("{tableName}", tableName.GetPrefixedName(migrationConfig.GetSchemaPrefixId()));

            var list = new List <string>(new[] { defaultKey, alternativeKey, alternativeKey2 }.Distinct());

            if (fallbackTemplates.Any())
            {
                list.AddRange(fallbackTemplates.SelectMany(x => new[]
                {
                    x.ReplaceIgnoreCase("{tableName}", tableName),
                    x.ReplaceIgnoreCase("{tableName}", tableName.TrimPrefixName(migrationConfig.GetSchemaPrefixId())),
                    x.ReplaceIgnoreCase("{tableName}", tableName.GetPrefixedName(migrationConfig.GetSchemaPrefixId())),
                }.Distinct()));
            }

            var keys = list.Distinct().ToArray();

            return(migrationConfig.GetAllMigrationConfigValues()?.GetValue(keys) ??
                   migrationConfig.GetDbConfig().GetAllDatabaseConfigValues()?.GetValue(keys));
        }
示例#3
0
 /// <summary>
 /// Resolve underlying <see cref="IConfiguration"/> to the implemented class of <see cref="IDbMigrationConfig"/>
 /// </summary>
 /// <param name="dbMigrationConfig"></param>
 /// <returns></returns>
 public static IConfiguration GetConfiguration(this IDbMigrationConfig dbMigrationConfig)
 {
     if (dbMigrationConfig != null && dbMigrationConfig is MsDbMigrationConfig msDbMigrationConfig)
     {
         return(msDbMigrationConfig.Configuration);
     }
     return(dbMigrationConfig?.GetDbConfig()?.GetConfiguration());
 }
 public DefaultOracleCustomMigrationProcessor(
     ILogger <DefaultOracleCustomMigrationProcessor> logger,
     IExtendedMigrationProcessorOracle processor,
     IDbMigrationConfig migrationConfig)
 {
     Logger          = logger;
     Processor       = processor;
     MigrationConfig = migrationConfig;
     Enabled         = MigrationConfig.GetDbConfig().DbType == SupportedDatabaseTypes.Oracle;
 }
示例#5
0
        /// <summary>
        /// Fetch config value for <paramref name="key"/>
        /// </summary>
        /// <param name="migrationConfig"></param>
        /// <param name="key"></param>
        /// <returns></returns>
        protected string GetConfigValue(IDbMigrationConfig migrationConfig, string key)
        {
            if (migrationConfig == null)
            {
                return(null);
            }

            return(migrationConfig.GetAllMigrationConfigValues()?.GetValue(key) ??
                   migrationConfig.GetDbConfig().GetAllDatabaseConfigValues()?.GetValue(key));
        }
示例#6
0
        private static string GetConnecionStringWithoutDatabase(this IDbMigrationConfig dbMigrationConfig)
        {
            var dbConfig = dbMigrationConfig.GetDbConfig();

            return(string.Format(ConnectionStringWithoutDatabaseTemplate,
                                 dbConfig.AdminUser.ToLower(),
                                 dbConfig.AdminPassword,
                                 dbConfig.Hostname.ToLower(),
                                 dbConfig.Port,
                                 dbConfig.Pooling));
        }