LinuxDoku / migratordotnet

Automatically exported from code.google.com/p/migratordotnet
0 stars 0 forks source link

SQLIte.NET problems with not null without defaults #142

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
--- What steps will reproduce the problem?
1. Create SQLite DB. Add table. Create field as not null without default 
value.
2. Create migration (try to rename created field).

--- What is the expected output? What do you see instead?
SQLite error. 

--- Please use labels and text to provide additional information.
Change SQLiteTransformationProvider.cs as described below (yes, I know, 
that this is not best solution.):

        public override void RenameColumn(string tableName, string 
oldColumnName, string newColumnName)
        {
            if (ColumnExists(tableName, newColumnName))
                throw new MigrationException(String.Format("Table '{0}' has 
column named '{1}' already", tableName, newColumnName));

            if (ColumnExists(tableName, oldColumnName)) 
            {
                string[] columnDefs = GetColumnDefs(tableName);
                string columnDef = Array.Find(columnDefs, delegate(string 
col) { return ColumnMatch(oldColumnName, col); });

                string newColumnDef = columnDef.Replace(oldColumnName, 
newColumnName);
                //begin deleting not null if not defining default value
                if ((newColumnDef.ToLower().Contains(" not null")) && 
(!newColumnDef.ToLower().Contains(" default ")))
                {
                    newColumnDef = newColumnDef.Replace(" not null", "");
                    newColumnDef = newColumnDef.Replace(" NOT NULL", "");
                }
                //end deleting not null if not defining default value

                AddColumn(tableName, newColumnDef);
                ExecuteQuery(String.Format("UPDATE {0} SET {1}={2}", 
tableName, newColumnName, oldColumnName));
                RemoveColumn(tableName, oldColumnName);
            }
        }

Original issue reported on code.google.com by it.advis...@gmail.com on 12 Mar 2010 at 4:47