/// <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));
        }
Esempio n. 2
0
 /// <summary>
 /// Constructor<br/>
 /// -------------<br/>
 /// AnonymousOperation is assigned with "NOOP"<br/>
 /// SchemaPrefixId is assigned with value from parameter <paramref name="migrationConfig"/> - property <see cref="IMigrationModel.SchemaPrefixId"/><br/>
 /// SchemaPrefixUniqueId is assigned with value from parameter <paramref name="migrationConfig"/> - property <see cref="IMigrationModel.SchemaPrefixUniqueId"/><br/>
 /// <br/>
 /// i.e:<br/>
 /// When configuration have database:migration:schemaPrefix:Id = "PR" and database:migration:schemaPrefix:UniqueId = "abode" <br/>
 /// SchemaPrefixId will be resolved to "PR"<br/>
 /// SchemaPrefixUniqueId will be resolved to "abode"<br/>
 /// </summary>
 /// <param name="migrationConfig"></param>
 public ChangeLogContext(IDbMigrationConfig migrationConfig)
     : this()
 {
     SchemaPrefixId       = migrationConfig?.GetSchemaPrefixId();
     SchemaPrefixUniqueId = migrationConfig?.GetSchemaPrefixUniqueId();
     InitMetadata(migrationConfig);
 }