Esempio n. 1
0
 def ddl_alter_table(self, ddl):
     with self.edit_table_schema(ddl.name, True) as table:
         if type(ddl.alteration) == statements.AddConstraint:
             constraint = ddl.alteration.constraint
             if type(constraint) == statements.UniqueConstraint:
                 table['indexes'][ddl.alteration.name] = {
                     'columns': constraint.cols,
                     'unique': True,
                 }
                 self.update_index(table, ddl.alteration.name)
             elif type(constraint) == statements.ForeignKey:
                 table['foreign_keys'][ddl.alteration.name] = {
                     'column': constraint.name,
                     'ref_table': constraint.ref_table,
                     'ref_cols': constraint.ref_cols,
                 }
                 self.update_fk(ddl.name, ddl.alteration.name)
             else:
                 import pdb; pdb.set_trace()
         elif type(ddl.alteration) == statements.AlterColumn:
             if type(ddl.alteration.alteration) == statements.SetDefault:
                 table['columns'][ddl.alteration.name]['default'] = \
                     json.loads(ddl.alteration.alteration.value)
             else:
                 import pdb; pdb.set_trace()
             proto.generate(table)
         else:
             import pdb; pdb.set_trace()
             1
Esempio n. 2
0
 def ddl_create_table(self, ddl):
     self.branch['tables/%s/objects' % ddl.name] = gitly.EMPTY
     with self.edit_table_schema(ddl.name, False) as table:
         table.update({
             'name': ddl.name,
             'columns': {},
             'indexes': {},
             'foreign_keys': {},
             'columns_order': [],
         })
         for column in ddl.columns:
             table['columns'][column.name] = column
             table['columns_order'].append(column.name)
             if column.unique:
                 idx_name = 'FIELD_UNIQUE_%s' % column.name
                 table['indexes'][idx_name] = {
                     'columns': [column.name],
                     'unique': True,
                 }
             elif column.primary_key:
                 idx_name = 'FIELD_PRIMARY_%s' % column.name
                 table['indexes'][idx_name] = {
                     'columns': [column.name],
                     'unique': True,
                 }
         proto.generate(table)