Пример #1
0
        public static async Task EnsureSchemaExists(this NpgsqlConnection conn, string schemaName, CancellationToken cancellation = default)
        {
            bool shouldClose = false;

            if (conn.State != ConnectionState.Open)
            {
                shouldClose = true;
                await conn.OpenAsync(cancellation);
            }

            try
            {
                await conn
                .CreateCommand(SchemaMigration.CreateSchemaStatementFor(schemaName))
                .ExecuteNonQueryAsync(cancellation);
            }
            finally
            {
                if (shouldClose)
                {
                    await conn.CloseAsync();
                }
            }
        }
Пример #2
0
 public static Task ResetSchema(this NpgsqlConnection conn, string schemaName)
 {
     return(conn.RunSql(DropStatementFor(schemaName, CascadeAction.Cascade), SchemaMigration.CreateSchemaStatementFor(schemaName)));
 }
Пример #3
0
 public static Task CreateSchema(this NpgsqlConnection conn, string schemaName)
 {
     return(conn.CreateCommand(SchemaMigration.CreateSchemaStatementFor(schemaName)).ExecuteNonQueryAsync());
 }
Пример #4
0
        public static async Task ApplyChanges(this ISchemaObject schemaObject, NpgsqlConnection conn)
        {
            var migration = await SchemaMigration.Determine(conn, new ISchemaObject[] { schemaObject });

            await migration.ApplyAll(conn, new DdlRules(), AutoCreate.CreateOrUpdate);
        }