[bitbake-devel] [PATCH 4/5] toaster: fix migration code for MySQL

Alex DAMIAN alexandru.damian at intel.com
Thu May 8 13:24:34 UTC 2014


From: Alexandru DAMIAN <alexandru.damian at intel.com>

This is a patch that fixes the 0004, 0005 migrations of the toaster
model to get them to properly work with MySQL.

These migrations had a conflict around Build.timespent field.
The sqlite3 constraits were not enough to detect the conflict, and
the migrations worked as expected.

MySQL objected to adding the field twice, so I did regenerate
the migrations with the correct model listing. The net effect
is the same, so the migrations work the same, but now we
can use these two migration on the MySQL and other more advanced
SQL engines.

Signed-off-by: Alexandru DAMIAN <alexandru.damian at intel.com>
---
 .../0004_auto__add_field_package_installed_name.py |  1 +
 ...e__add_target_file__add_field_variablehistor.py | 56 +++++++---------------
 2 files changed, 19 insertions(+), 38 deletions(-)

diff --git a/lib/toaster/orm/migrations/0004_auto__add_field_package_installed_name.py b/lib/toaster/orm/migrations/0004_auto__add_field_package_installed_name.py
index ca114de..fc5ff53 100644
--- a/lib/toaster/orm/migrations/0004_auto__add_field_package_installed_name.py
+++ b/lib/toaster/orm/migrations/0004_auto__add_field_package_installed_name.py
@@ -34,6 +34,7 @@ class Migration(SchemaMigration):
             'machine': ('django.db.models.fields.CharField', [], {'max_length': '100'}),
             'outcome': ('django.db.models.fields.IntegerField', [], {'default': '2'}),
             'started_on': ('django.db.models.fields.DateTimeField', [], {}),
+            'timespent': ('django.db.models.fields.IntegerField', [], {'default': '0'}),
             'warnings_no': ('django.db.models.fields.IntegerField', [], {'default': '0'})
         },
         u'orm.layer': {
diff --git a/lib/toaster/orm/migrations/0005_auto__add_target_image_file__add_target_file__add_field_variablehistor.py b/lib/toaster/orm/migrations/0005_auto__add_target_image_file__add_target_file__add_field_variablehistor.py
index a55451c..fd1d153 100644
--- a/lib/toaster/orm/migrations/0005_auto__add_target_image_file__add_target_file__add_field_variablehistor.py
+++ b/lib/toaster/orm/migrations/0005_auto__add_target_image_file__add_target_file__add_field_variablehistor.py
@@ -8,15 +8,6 @@ from django.db import models
 class Migration(SchemaMigration):
 
     def forwards(self, orm):
-        # Adding model 'Target_Image_File'
-        db.create_table(u'orm_target_image_file', (
-            (u'id', self.gf('django.db.models.fields.AutoField')(primary_key=True)),
-            ('target', self.gf('django.db.models.fields.related.ForeignKey')(to=orm['orm.Target'])),
-            ('file_name', self.gf('django.db.models.fields.FilePathField')(max_length=100)),
-            ('file_size', self.gf('django.db.models.fields.IntegerField')()),
-        ))
-        db.send_create_signal(u'orm', ['Target_Image_File'])
-
         # Adding model 'Target_File'
         db.create_table(u'orm_target_file', (
             (u'id', self.gf('django.db.models.fields.AutoField')(primary_key=True)),
@@ -32,6 +23,15 @@ class Migration(SchemaMigration):
         ))
         db.send_create_signal(u'orm', ['Target_File'])
 
+        # Adding model 'Target_Image_File'
+        db.create_table(u'orm_target_image_file', (
+            (u'id', self.gf('django.db.models.fields.AutoField')(primary_key=True)),
+            ('target', self.gf('django.db.models.fields.related.ForeignKey')(to=orm['orm.Target'])),
+            ('file_name', self.gf('django.db.models.fields.FilePathField')(max_length=100)),
+            ('file_size', self.gf('django.db.models.fields.IntegerField')()),
+        ))
+        db.send_create_signal(u'orm', ['Target_Image_File'])
+
         # Adding field 'VariableHistory.value'
         db.add_column(u'orm_variablehistory', 'value',
                       self.gf('django.db.models.fields.TextField')(default='', blank=True),
@@ -49,11 +49,6 @@ class Migration(SchemaMigration):
         # Deleting field 'Build.image_fstypes'
         db.delete_column(u'orm_build', 'image_fstypes')
 
-        # Adding field 'Build.timespent'
-        db.add_column(u'orm_build', 'timespent',
-                      self.gf('django.db.models.fields.IntegerField')(default=0),
-                      keep_default=False)
-
         # Adding field 'LogMessage.task'
         db.add_column(u'orm_logmessage', 'task',
                       self.gf('django.db.models.fields.related.ForeignKey')(to=orm['orm.Task'], null=True, blank=True),
@@ -70,12 +65,12 @@ class Migration(SchemaMigration):
         # Removing unique constraint on 'Task', fields ['build', 'recipe', 'task_name']
         db.delete_unique(u'orm_task', ['build_id', 'recipe_id', 'task_name'])
 
-        # Deleting model 'Target_Image_File'
-        db.delete_table(u'orm_target_image_file')
-
         # Deleting model 'Target_File'
         db.delete_table(u'orm_target_file')
 
+        # Deleting model 'Target_Image_File'
+        db.delete_table(u'orm_target_image_file')
+
         # Deleting field 'VariableHistory.value'
         db.delete_column(u'orm_variablehistory', 'value')
 
@@ -84,36 +79,21 @@ class Migration(SchemaMigration):
                       self.gf('django.db.models.fields.TextField')(default='', blank=True),
                       keep_default=False)
 
-
-        # User chose to not deal with backwards NULL issues for 'Target.file_name'
-        raise RuntimeError("Cannot reverse this migration. 'Target.file_name' and its values cannot be restored.")
-        
-        # The following code is provided here to aid in writing a correct migration        # Adding field 'Target.file_name'
+        # Adding field 'Target.file_name'
         db.add_column(u'orm_target', 'file_name',
-                      self.gf('django.db.models.fields.CharField')(max_length=100),
+                      self.gf('django.db.models.fields.CharField')(default='', max_length=100),
                       keep_default=False)
 
-
-        # User chose to not deal with backwards NULL issues for 'Target.file_size'
-        raise RuntimeError("Cannot reverse this migration. 'Target.file_size' and its values cannot be restored.")
-        
-        # The following code is provided here to aid in writing a correct migration        # Adding field 'Target.file_size'
+        # Adding field 'Target.file_size'
         db.add_column(u'orm_target', 'file_size',
-                      self.gf('django.db.models.fields.IntegerField')(),
+                      self.gf('django.db.models.fields.IntegerField')(default=0),
                       keep_default=False)
 
-
-        # User chose to not deal with backwards NULL issues for 'Build.image_fstypes'
-        raise RuntimeError("Cannot reverse this migration. 'Build.image_fstypes' and its values cannot be restored.")
-        
-        # The following code is provided here to aid in writing a correct migration        # Adding field 'Build.image_fstypes'
+        # Adding field 'Build.image_fstypes'
         db.add_column(u'orm_build', 'image_fstypes',
-                      self.gf('django.db.models.fields.CharField')(max_length=100),
+                      self.gf('django.db.models.fields.CharField')(default='', max_length=100),
                       keep_default=False)
 
-        # Deleting field 'Build.timespent'
-        db.delete_column(u'orm_build', 'timespent')
-
         # Deleting field 'LogMessage.task'
         db.delete_column(u'orm_logmessage', 'task_id')
 
-- 
1.9.1




More information about the bitbake-devel mailing list