Пример #1
0
 public async Task <bool> ExistsAsync(MigratorDatabase database, CancellationToken cancellation = default)
 {
     return(0 != await database.SingleAsync <int>($@"
             SELECT Count(*) FROM sys.tables AS tables
             JOIN sys.schemas AS schemas on tables.schema_id = schemas.schema_id
             WHERE concat(schemas.name, '.', tables.name) = '{TableName}' AND type = 'U'", cancellation : cancellation));
 }
Пример #2
0
        private async Task CreateSchemaIfNotExistingAsync(MigratorDatabase database, CancellationToken cancellation = default)
        {
            var schemaCount = await database.SingleAsync <int>($@"
                    SELECT Count(schema_name) 
                    FROM information_schema.schemata 
                    WHERE schema_name = '{SchemaName}'", cancellation : cancellation);

            if (schemaCount == 1)
            {
                return;
            }

            try
            {
                await database.ExecuteAsync($"CREATE SCHEMA {SchemaName}", cancellation : cancellation);
            }
            catch (SqlException e) when(e.Number == ThereIsAlreadyAnObjectNamedXxxInTheDatabase)
            {
            }
        }