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(); } } }
public static Task ResetSchema(this NpgsqlConnection conn, string schemaName) { return(conn.RunSql(DropStatementFor(schemaName, CascadeAction.Cascade), SchemaMigration.CreateSchemaStatementFor(schemaName))); }
public static Task CreateSchema(this NpgsqlConnection conn, string schemaName) { return(conn.CreateCommand(SchemaMigration.CreateSchemaStatementFor(schemaName)).ExecuteNonQueryAsync()); }
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); }