示例#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());
 }