Exemple #1
0
        /// <summary>
        /// 异步检查确保数据库和表已创建
        /// </summary>
        /// <param name="database">数据库</param>
        /// <param name="schemas">方案</param>
        /// <param name="cancellationToken">取消令牌</param>
        /// <returns></returns>
        public static async Task <bool> EnsureCreatedAsync([NotNull] this DatabaseFacade database, string[] schemas, CancellationToken cancellationToken = default(CancellationToken))
        {
            Check.NotNull(database, nameof(database));

            if (schemas == null || schemas.Length == 0)
            {
                return(await database.EnsureCreatedAsync());
            }
            OracleDatabaseCreator db = (OracleDatabaseCreator)database.GetService <IRelationalDatabaseCreator>();

            using (new TransactionScope(TransactionScopeOption.Suppress, TransactionScopeAsyncFlowOption.Enabled))
            {
                if (!(await db.ExistsAsync(cancellationToken)))
                {
                    await db.CreateAsync(cancellationToken);

                    await db.CreateTablesAsync(cancellationToken);

                    return(true);
                }
                if (!(await db.HasTablesAsyncWithSchemaOption(schemas, cancellationToken)))
                {
                    await db.CreateTablesAsync(cancellationToken);

                    return(true);
                }
            }
            return(false);
        }
Exemple #2
0
        /// <summary>
        /// 异步确保被删除
        /// </summary>
        /// <param name="database">数据库</param>
        /// <param name="schemas">方案</param>
        /// <param name="cancellationToken">取消令牌</param>
        /// <returns></returns>
        public static async Task <bool> EnsureDeletedAsync([NotNull] this DatabaseFacade database, string[] schemas, CancellationToken cancellationToken = default(CancellationToken))
        {
            Check.NotNull(database, nameof(database));

            if (schemas == null || schemas.Length == 0)
            {
                return(await database.EnsureDeletedAsync());
            }
            OracleDatabaseCreator oracleDBCreator = (OracleDatabaseCreator)database.GetService <IRelationalDatabaseCreator>();

            if (await oracleDBCreator.ExistsAsync(cancellationToken))
            {
                await oracleDBCreator.DeleteAsyncWithSchemaOption(schemas, cancellationToken);

                return(true);
            }
            return(false);
        }