Merge pull request #167 from meanmail/develop

Support for adding a column to the beginning of a table
This commit is contained in:
Kobi Tal 2021-10-21 09:39:18 +03:00 committed by GitHub
commit da591dc649
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -83,10 +83,12 @@ class AlterTable(ModelOperation):
is_regular_field = not (field.materialized or field.alias) is_regular_field = not (field.materialized or field.alias)
if name not in table_fields: if name not in table_fields:
logger.info(' Add column %s', name) logger.info(' Add column %s', name)
assert prev_name, 'Cannot add a column to the beginning of the table'
cmd = 'ADD COLUMN %s %s' % (name, field.get_sql(db=database)) cmd = 'ADD COLUMN %s %s' % (name, field.get_sql(db=database))
if is_regular_field: if is_regular_field:
if prev_name:
cmd += ' AFTER %s' % prev_name cmd += ' AFTER %s' % prev_name
else:
cmd += ' FIRST'
self._alter_table(database, cmd) self._alter_table(database, cmd)
if is_regular_field: if is_regular_field: