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