Changeset 5794 for django/branches/schema-evolution/tests
- Timestamp:
- 08/03/07 17:38:44 (1 year ago)
- Files:
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
django/branches/schema-evolution/tests/modeltests/schema_evolution/models.py
r5792 r5794 23 23 24 24 class Muebles(models.Model): 25 tipo = models.CharField(maxlength=40 )25 tipo = models.CharField(maxlength=40, default="woot") 26 26 # new fields 27 27 fecha_publicacion = models.DateTimeField('date published') … … 98 98 0L\n0L 99 99 100 # delete a datetime column pair, so it looks like we've recently added a datetime field100 # delete a datetime column, so it looks like we've recently added a datetime field 101 101 >>> for sql in backend.get_drop_column_sql( 'schema_evolution_muebles', 'fecha_publicacion' ): print sql; cursor.execute(sql) 102 102 ALTER TABLE `schema_evolution_muebles` DROP COLUMN `fecha_publicacion`; … … 104 104 >>> management.get_sql_evolution(app) 105 105 ['ALTER TABLE `schema_evolution_muebles` ADD COLUMN `fecha_publicacion` datetime NOT NULL;'] 106 107 # reset the db 108 >>> cursor.execute('DROP TABLE schema_evolution_muebles;'); cursor.execute(create_table_sql[1]) 109 0L\n0L 110 111 # delete a column with a default value, so it looks like we've recently added a column 112 >>> for sql in backend.get_drop_column_sql( 'schema_evolution_muebles', 'tipo' ): print sql; cursor.execute(sql) 113 ALTER TABLE `schema_evolution_muebles` DROP COLUMN `tipo`; 114 0L 115 >>> management.get_sql_evolution(app) 116 ['ALTER TABLE `schema_evolution_muebles` ADD COLUMN `tipo` varchar(40) NOT NULL DEFAULT `woot`;'] 106 117 107 118 """ … … 125 136 126 137 # add a column, so it looks like we've recently deleted a field 127 >>> for sql in backend.get_add_column_sql( 'schema_evolution_person', 'gender_nothere', 'varchar(1)', True, False, False ): cursor.execute(sql)138 >>> for sql in backend.get_add_column_sql( 'schema_evolution_person', 'gender_nothere', 'varchar(1)', True, False, False, None ): cursor.execute(sql) 128 139 >>> management.get_sql_evolution(app) 129 140 ['-- warning: the following may cause data loss', u'ALTER TABLE "schema_evolution_person" DROP COLUMN "gender_nothere";', '-- end warning'] … … 149 160 150 161 # change column flags, so it looks like we've recently changed a column flag 151 >>> for sql in backend.get_change_column_def_sql( 'schema_evolution_person', 'name', 'varchar(10)', True, False, False ): cursor.execute(sql)162 >>> for sql in backend.get_change_column_def_sql( 'schema_evolution_person', 'name', 'varchar(10)', True, False, False, None ): cursor.execute(sql) 152 163 >>> management.get_sql_evolution(app) 153 164 ['ALTER TABLE "schema_evolution_person" ADD COLUMN "name_tmp" varchar(20);', 'UPDATE "schema_evolution_person" SET "name_tmp" = "name";', 'ALTER TABLE "schema_evolution_person" DROP COLUMN "name";', 'ALTER TABLE "schema_evolution_person" RENAME COLUMN "name_tmp" TO "name";', 'ALTER TABLE "schema_evolution_person" ALTER COLUMN "name" SET NOT NULL;'] … … 161 172 >>> management.get_sql_evolution(app) 162 173 ['ALTER TABLE "schema_evolution_muebles" ADD COLUMN "fecha_publicacion" timestamp with time zone;', 'ALTER TABLE "schema_evolution_muebles" ALTER COLUMN "fecha_publicacion" SET NOT NULL;'] 174 175 # reset the db 176 >>> cursor.execute('DROP TABLE schema_evolution_muebles;'); cursor.execute(create_table_sql[1]) 177 178 # delete a column with a default value, so it looks like we've recently added a column 179 >>> for sql in backend.get_drop_column_sql( 'schema_evolution_muebles', 'tipo' ): print sql; cursor.execute(sql) 180 ALTER TABLE "schema_evolution_muebles" DROP COLUMN "tipo"; 181 >>> management.get_sql_evolution(app) 182 ['ALTER TABLE "schema_evolution_muebles" ADD COLUMN "tipo" varchar(40);', 'ALTER TABLE "schema_evolution_muebles" ALTER COLUMN "tipo" SET DEFAULT "woot";', 'ALTER TABLE "schema_evolution_muebles" ALTER COLUMN "tipo" SET NOT NULL;'] 163 183 """ 164 184 … … 277 297 ['ALTER TABLE "schema_evolution_muebles" ADD COLUMN "fecha_publicacion" datetime NOT NULL;'] 278 298 279 280 """ 281 299 # reset the db 300 >>> cursor.execute('DROP TABLE schema_evolution_muebles;').__class__ 301 <class 'django.db.backends.sqlite3.base.SQLiteCursorWrapper'> 302 >>> cursor.execute(create_table_sql[1]).__class__ 303 <class 'django.db.backends.sqlite3.base.SQLiteCursorWrapper'> 304 305 # delete a column with a default value, so it looks like we've recently added a column 306 >>> for sql in ['DROP TABLE schema_evolution_muebles;','CREATE TABLE "schema_evolution_muebles" ("id" integer NOT NULL UNIQUE PRIMARY KEY,"fecha_publicacion" datetime NOT NULL);']: cursor.execute(sql).__class__ 307 <class 'django.db.backends.sqlite3.base.SQLiteCursorWrapper'> 308 <class 'django.db.backends.sqlite3.base.SQLiteCursorWrapper'> 309 >>> management.get_sql_evolution(app) 310 ['ALTER TABLE "schema_evolution_muebles" ADD COLUMN "tipo" varchar(40) NOT NULL DEFAULT "woot";'] 311 312 """ 313
