Пример #1
0
 /// <summary>
 /// 重命名 Sequence
 /// </summary>
 public static void RenameSequence(this IDbMigration migration, string name, string newName,
                                   bool suppressTransaction = false)
 {
     migration.AddOperation(new SqlOperation($"exec sp_rename '{name}', '{newName}'")
     {
         SuppressTransaction = suppressTransaction
     });
 }
Пример #2
0
        private static void AddSqlOperation(this IDbMigration migration, string sql, bool suppressTransaction = false, object anonymousArguments = null)
        {
            var operation = new SqlOperation(sql, anonymousArguments)
            {
                SuppressTransaction = suppressTransaction
            };

            migration.AddOperation(operation);
        }
Пример #3
0
 /// <summary>
 /// 删除指定 Sequence
 /// </summary>
 public static void DropSequence(this IDbMigration migration, string sequenceName,
                                 bool suppressTransaction = false)
 {
     migration.AddOperation(
         new SqlOperation($"DROP SEQUENCE {sequenceName}")
     {
         SuppressTransaction = suppressTransaction
     });
 }
Пример #4
0
 /// <summary>
 /// 创建一个 No Cache 的 Sequence
 /// </summary>
 public static void CreateSequence(this IDbMigration migration, string sequenceName,
                                   bool suppressTransaction = false)
 {
     migration.AddOperation(
         new SqlOperation($"CREATE SEQUENCE {sequenceName} AS bigint START WITH 1 INCREMENT BY 1 NO CACHE")
     {
         SuppressTransaction = suppressTransaction
     });
 }
Пример #5
0
 /// <summary>
 /// 为指定列添加默认值约束
 /// </summary>
 public static void AddDefaultContraint(this IDbMigration migration, string tableName, string colName,
                                        string defaultValue, bool suppressTransaction = false)
 {
     migration.AddOperation(
         new SqlOperation($"ALTER TABLE {tableName} ADD DEFAULT {defaultValue} FOR {colName};")
     {
         SuppressTransaction = suppressTransaction
     });
 }
Пример #6
0
        public static void DeleteDefaultConstraint(this IDbMigration migration, string tableName, string colName, bool suppressTransaction = false)
        {
            var sql = new SqlOperation(
                $"DECLARE @SQL varchar(1000) " +
                $"SET @SQL='ALTER TABLE {tableName} DROP CONSTRAINT ['+(SELECT name FROM sys.default_constraints WHERE parent_object_id = object_id('{tableName}') AND col_name(parent_object_id, parent_column_id) = '{colName}')+']'; " +
                $"PRINT @SQL; " +
                $"EXEC(@SQL);")
            {
                SuppressTransaction = suppressTransaction
            };

            migration.AddOperation(sql);
        }
Пример #7
0
        public static void DeleteDefaultConstraint(this IDbMigration migration, string tableName, string colName, bool suppressTransaction = false)
        {
            // see https://stackoverflow.com/questions/17894906/ef-migration-for-changing-data-type-of-columns
            // (function name there with typo: DeleteDefaultContraint)

            var sql = new SqlOperation(String.Format(@"DECLARE @SQL varchar(1000)
        SET @SQL='ALTER TABLE {0} DROP CONSTRAINT ['+(SELECT name
        FROM sys.default_constraints
        WHERE parent_object_id = object_id('{0}')
        AND col_name(parent_object_id, parent_column_id) = '{1}')+']';
        PRINT @SQL;
        EXEC(@SQL);", tableName, colName))
            {
                SuppressTransaction = suppressTransaction
            };

            migration.AddOperation(sql);
        }
Пример #8
0
 public static void Comment(this IDbMigration migration, string text, object anonymousArguments = null)
 {
     migration.AddOperation(new CommentOperation(text, anonymousArguments));
 }