コード例 #1
0
def upgrade(migrate_engine):
    print(__doc__)
    metadata.bind = migrate_engine
    metadata.reflect()

    ToolShedRepository_table = Table("tool_shed_repository",
                                     metadata,
                                     autoload=True)
    c = Column("metadata", JSONType(), nullable=True)
    add_column(c, ToolShedRepository_table, metadata)
    c = Column("includes_datatypes", Boolean, index=True, default=False)
    add_column(c,
               ToolShedRepository_table,
               metadata,
               index_name="ix_tool_shed_repository_includes_datatypes")
    try:
        migrate_engine.execute(
            "UPDATE tool_shed_repository SET includes_datatypes=%s" %
            engine_false(migrate_engine))
    except Exception:
        log.exception(
            "Updating column 'includes_datatypes' of table 'tool_shed_repository' failed."
        )
    c = Column("update_available", Boolean, default=False)
    add_column(c, ToolShedRepository_table, metadata)
    try:
        migrate_engine.execute(
            "UPDATE tool_shed_repository SET update_available=%s" %
            engine_false(migrate_engine))
    except Exception:
        log.exception(
            "Updating column 'update_available' of table 'tool_shed_repository' failed."
        )
コード例 #2
0
def upgrade(migrate_engine):
    metadata.bind = migrate_engine
    print(__doc__)
    metadata.reflect()
    ToolShedRepository_table = Table( "tool_shed_repository", metadata, autoload=True )
    c = Column( "metadata", JSONType(), nullable=True )
    try:
        c.create( ToolShedRepository_table )
        assert c is ToolShedRepository_table.c.metadata
    except Exception:
        log.exception("Adding metadata column to the tool_shed_repository table failed.")
    c = Column( "includes_datatypes", Boolean, index=True, default=False )
    try:
        c.create( ToolShedRepository_table, index_name="ix_tool_shed_repository_includes_datatypes")
        assert c is ToolShedRepository_table.c.includes_datatypes
        migrate_engine.execute( "UPDATE tool_shed_repository SET includes_datatypes=%s" % engine_false(migrate_engine))
    except Exception:
        log.exception("Adding includes_datatypes column to the tool_shed_repository table failed.")
    c = Column( "update_available", Boolean, default=False )
    try:
        c.create( ToolShedRepository_table )
        assert c is ToolShedRepository_table.c.update_available
        migrate_engine.execute( "UPDATE tool_shed_repository SET update_available=%s" % engine_false(migrate_engine))
    except Exception:
        log.exception("Adding update_available column to the tool_shed_repository table failed.")
コード例 #3
0
def upgrade(migrate_engine):
    metadata.bind = migrate_engine
    print(__doc__)
    metadata.reflect()
    try:
        Request_table = Table( "request", metadata, autoload=True )
    except NoSuchTableError:
        Request_table = None
        log.debug( "Failed loading table 'request'" )

    if Request_table is not None:
        # create the column again as JSONType
        try:
            col = Column( "notification", JSONType() )
            col.create( Request_table )
            assert col is Request_table.c.notification
        except Exception as e:
            log.debug( "Creating column 'notification' in the 'request' table failed: %s" % ( str( e ) ) )

        cmd = "SELECT id, user_id, notify FROM request"
        result = migrate_engine.execute( cmd )
        for r in result:
            id = int(r[0])
            notify_new = dict(email=[], sample_states=[], body='', subject='')
            cmd = "UPDATE request SET notification='%s' WHERE id=%i" % (dumps(notify_new), id)
            migrate_engine.execute( cmd )

        # remove the 'notify' column for non-sqlite databases.
        if migrate_engine.name != 'sqlite':
            try:
                Request_table.c.notify.drop()
            except Exception as e:
                log.debug( "Deleting column 'notify' from the 'request' table failed: %s" % ( str( e ) ) )
コード例 #4
0
def downgrade(migrate_engine):
    metadata.bind = migrate_engine
    metadata.reflect()

    RequestType_table = Table("request_type", metadata, autoload=True)
    # create the 'datatx_info' column
    col = Column("datatx_info", JSONType())
    add_column(col, RequestType_table, metadata)
    # restore the datatx_info column data in the request_type table with data from
    # the sequencer and the form_values table
    cmd = "SELECT request_type.id, form_values.content "\
          + " FROM request_type, sequencer, form_values "\
          + " WHERE request_type.sequencer_id=sequencer.id AND sequencer.form_values_id=form_values.id "\
          + " ORDER  BY request_type.id ASC"
    result = migrate_engine.execute(cmd)
    for row in result:
        request_type_id = row[0]
        seq_values = loads(str(row[1]))
        # create the datatx_info json dict
        datatx_info = dumps(dict(host=seq_values.get('field_0', ''),
                                 username=seq_values.get('field_1', ''),
                                 password=seq_values.get('field_2', ''),
                                 data_dir=seq_values.get('field_3', ''),
                                 rename_dataset=seq_values.get('field_4', '')))
        # update the column
        cmd = "UPDATE request_type SET datatx_info='%s' WHERE id=%i" % (datatx_info, request_type_id)
        migrate_engine.execute(cmd)
    # delete foreign key field to the sequencer table in the request_type table
    drop_column('sequencer_id', RequestType_table)
コード例 #5
0
def upgrade(migrate_engine):
    print(__doc__)
    metadata.bind = migrate_engine
    metadata.reflect()

    # Add the datatx_info column in 'request_type' table
    col = Column("datatx_info", JSONType())
    add_column(col, 'request_type', metadata)

    # Delete the library_id column in 'request' table
    Request_table = Table("request", metadata, autoload=True)
    drop_column('library_id', Request_table)

    # Delete the folder_id column in 'request' table
    drop_column('folder_id', Request_table)

    # Add the dataset_files column in 'sample' table
    Sample_table = Table("sample", metadata, autoload=True)
    col = Column("dataset_files", JSONType())
    add_column(col, Sample_table)

    # Add the library_id column in 'sample' table
    # SQLAlchemy Migrate has a bug when adding a column with both a ForeignKey and a index in SQLite
    if migrate_engine.name != 'sqlite':
        col = Column("library_id",
                     Integer,
                     ForeignKey("library.id"),
                     index=True)
    else:
        col = Column("library_id", Integer, index=True)
    add_column(col, Sample_table, index_name='ix_sample_library_id')

    # Add the library_id column in 'sample' table
    # SQLAlchemy Migrate has a bug when adding a column with both a ForeignKey and a index in SQLite
    if migrate_engine.name != 'sqlite':
        col = Column("folder_id",
                     Integer,
                     ForeignKey("library_folder.id"),
                     index=True)
    else:
        col = Column("folder_id", Integer, index=True)
    add_column(col, Sample_table, index_name='ix_sample_library_folder_id')
コード例 #6
0
def upgrade(migrate_engine):
    print(__doc__)
    metadata.bind = migrate_engine
    metadata.reflect()

    # Add the datatx_info column in 'request_type' table
    col = Column("datatx_info", JSONType())
    add_column(col, 'request_type', metadata)

    # Delete the library_id column in 'request' table
    Request_table = Table("request", metadata, autoload=True)
    # TODO: Dropping a column used in a foreign key fails in MySQL, need to remove the FK first.
    drop_column('library_id', Request_table)

    # Delete the folder_id column in 'request' table
    # TODO: Dropping a column used in a foreign key fails in MySQL, need to remove the FK first.
    drop_column('folder_id', Request_table)

    # Add the dataset_files column in 'sample' table
    Sample_table = Table("sample", metadata, autoload=True)
    col = Column("dataset_files", JSONType())
    add_column(col, Sample_table, metadata)

    # Add the library_id column in 'sample' table
    col = Column("library_id", Integer, ForeignKey("library.id"), index=True)
    add_column(col, Sample_table, metadata, index_name='ix_sample_library_id')

    # Add the library_id column in 'sample' table
    col = Column("folder_id",
                 Integer,
                 ForeignKey("library_folder.id"),
                 index=True)
    add_column(col,
               Sample_table,
               metadata,
               index_name='ix_sample_library_folder_id')
コード例 #7
0
def downgrade(migrate_engine):
    metadata.bind = migrate_engine
    metadata.reflect()

    try:
        RequestType_table = Table("request_type", metadata, autoload=True)
    except NoSuchTableError:
        RequestType_table = None
        log.debug("Failed loading table 'request_type'")
    if RequestType_table is not None:
        # create the 'datatx_info' column
        try:
            col = Column("datatx_info", JSONType())
            col.create(RequestType_table)
            assert col is RequestType_table.c.datatx_info
        except Exception:
            log.exception(
                "Creating column 'datatx_info' in the 'request_type' table failed."
            )
        # restore the datatx_info column data in the request_type table with data from
        # the sequencer and the form_values table
        cmd = "SELECT request_type.id, form_values.content "\
              + " FROM request_type, sequencer, form_values "\
              + " WHERE request_type.sequencer_id=sequencer.id AND sequencer.form_values_id=form_values.id "\
              + " ORDER  BY request_type.id ASC"
        result = migrate_engine.execute(cmd)
        for row in result:
            request_type_id = row[0]
            seq_values = loads(str(row[1]))
            # create the datatx_info json dict
            datatx_info = dumps(
                dict(host=seq_values.get('field_0', ''),
                     username=seq_values.get('field_1', ''),
                     password=seq_values.get('field_2', ''),
                     data_dir=seq_values.get('field_3', ''),
                     rename_dataset=seq_values.get('field_4', '')))
            # update the column
            cmd = "UPDATE request_type SET datatx_info='%s' WHERE id=%i" % (
                datatx_info, request_type_id)
            migrate_engine.execute(cmd)
        # delete foreign key field to the sequencer table in the request_type table
        try:
            RequestType_table.c.sequencer_id.drop()
        except Exception:
            log.exception(
                "Deleting column 'sequencer_id' in the 'request_type' table failed."
            )
def upgrade(migrate_engine):
    metadata.bind = migrate_engine
    print __doc__
    metadata.reflect()
    ToolShedRepository_table = Table("tool_shed_repository",
                                     metadata,
                                     autoload=True)
    c = Column("metadata", JSONType(), nullable=True)
    try:
        c.create(ToolShedRepository_table)
        assert c is ToolShedRepository_table.c.metadata
    except Exception, e:
        print "Adding metadata column to the tool_shed_repository table failed: %s" % str(
            e)
        log.debug(
            "Adding metadata column to the tool_shed_repository table failed: %s"
            % str(e))
コード例 #9
0
def upgrade(migrate_engine):
    metadata.bind = migrate_engine
    print __doc__
    # Load existing tables
    metadata.reflect()
    # retuest_type table
    try:
        RequestType_table = Table( "request_type", metadata, autoload=True )
    except NoSuchTableError:
        RequestType_table = None
        log.debug( "Failed loading table request_type" )
    if RequestType_table is not None:
        # Add the datatx_info column in 'request_type' table
        try:
            col = Column( "datatx_info", JSONType() )
            col.create( RequestType_table )
            assert col is RequestType_table.c.datatx_info
        except Exception, e:
            log.debug( "Adding column 'datatx_info' to request_type table failed: %s" % ( str( e ) ) )
コード例 #10
0
def upgrade(migrate_engine):
    print(__doc__)
    metadata.bind = migrate_engine
    metadata.reflect()

    # Create the folder_id column
    col = Column("folder_id",
                 Integer,
                 ForeignKey('library_folder.id'),
                 index=True)
    add_column(col, 'request', metadata, index_name='ix_request_folder_id')
    # Create the type column in form_definition
    FormDefinition_table = Table("form_definition", metadata, autoload=True)
    col = Column("type", TrimmedString(255), index=True)
    add_column(col,
               FormDefinition_table,
               metadata,
               index_name='ix_form_definition_type')
    col = Column("layout", JSONType())
    add_column(col, FormDefinition_table, metadata)
コード例 #11
0
def upgrade(migrate_engine):
    print(__doc__)
    metadata.bind = migrate_engine
    metadata.reflect()

    Request_table = Table("request", metadata, autoload=True)

    # create the column again as JSONType
    col = Column("notification", JSONType())
    add_column(col, Request_table)

    cmd = "SELECT id, user_id, notify FROM request"
    result = migrate_engine.execute(cmd)
    for r in result:
        id = int(r[0])
        notify_new = dict(email=[], sample_states=[], body='', subject='')
        cmd = "UPDATE request SET notification='%s' WHERE id=%i" % (
            dumps(notify_new), id)
        migrate_engine.execute(cmd)

    # SQLAlchemy Migrate has a bug when dropping a boolean column in SQLite
    if migrate_engine.name != 'sqlite':
        drop_column('notify', Request_table)
コード例 #12
0
def upgrade(migrate_engine):
    metadata.bind = migrate_engine
    print(__doc__)
    # Load existing tables
    metadata.reflect()
    # retuest_type table
    try:
        RequestType_table = Table("request_type", metadata, autoload=True)
    except NoSuchTableError:
        RequestType_table = None
        log.debug("Failed loading table request_type")
    if RequestType_table is not None:
        # Add the datatx_info column in 'request_type' table
        try:
            col = Column("datatx_info", JSONType())
            col.create(RequestType_table)
            assert col is RequestType_table.c.datatx_info
        except Exception:
            log.exception(
                "Adding column 'datatx_info' to request_type table failed.")
    # request table
    try:
        Request_table = Table("request", metadata, autoload=True)
    except NoSuchTableError:
        Request_table = None
        log.debug("Failed loading table request")
    if Request_table is not None:
        # Delete library_id & folder_id columns in the table 'request'.
        # if Galaxy is running on sqlite, the delete/recreate the table
        # otherwise remove the specific columns
        if migrate_engine.name == 'sqlite':
            # create a temporary table
            RequestTemp_table = Table(
                'request_temp', metadata,
                Column("id", Integer, primary_key=True),
                Column("create_time", DateTime, default=now),
                Column("update_time", DateTime, default=now, onupdate=now),
                Column("name", TrimmedString(255), nullable=False),
                Column("desc", TEXT),
                Column("form_values_id",
                       Integer,
                       ForeignKey("form_values.id"),
                       index=True),
                Column("request_type_id",
                       Integer,
                       ForeignKey("request_type.id"),
                       index=True),
                Column("user_id",
                       Integer,
                       ForeignKey("galaxy_user.id"),
                       index=True),
                Column("deleted", Boolean, index=True, default=False))
            try:
                RequestTemp_table.create()
            except Exception:
                log.exception("Creating request_temp table failed.")
            # insert all the rows from the request table to the request_temp table
            cmd = "INSERT INTO request_temp SELECT id, create_time, " + \
                "update_time, name, desc, form_values_id, request_type_id, " + \
                "user_id, deleted FROM request;"
            migrate_engine.execute(cmd)
            # delete the 'request' table
            try:
                Request_table.drop()
            except Exception:
                log.exception("Dropping request table failed.")
            # rename table request_temp to request
            cmd = "ALTER TABLE request_temp RENAME TO request"
            migrate_engine.execute(cmd)
        else:
            # Delete the library_id column in 'request' table
            try:
                Request_table.c.library_id.drop()
            except Exception:
                log.exception(
                    "Deleting column 'library_id' to request table failed.")
            # Delete the folder_id column in 'request' table
            try:
                Request_table.c.folder_id.drop()
            except Exception:
                log.exception(
                    "Deleting column 'folder_id' to request table failed.")
    # sample table
    try:
        Sample_table = Table("sample", metadata, autoload=True)
    except NoSuchTableError:
        Sample_table = None
        log.debug("Failed loading table sample")
    if Sample_table is not None:
        # Add the dataset_files column in 'sample' table
        try:
            col = Column("dataset_files", JSONType())
            col.create(Sample_table)
            assert col is Sample_table.c.dataset_files
        except Exception:
            log.exception(
                "Adding column 'dataset_files' to sample table failed.")
        # library table
        try:
            Library_table = Table("library", metadata, autoload=True)
        except NoSuchTableError:
            Library_table = None
            log.debug("Failed loading table library")
        if Library_table is not None:
            # Add the library_id column in 'sample' table
            try:
                if migrate_engine.name != 'sqlite':
                    col = Column("library_id",
                                 Integer,
                                 ForeignKey("library.id"),
                                 index=True)
                else:
                    col = Column("library_id", Integer, index=True)
                col.create(Sample_table, index_name='ix_sample_library_id')
                assert col is Sample_table.c.library_id
            except Exception:
                log.exception(
                    "Adding column 'library_id' to sample table failed.")
        # library_folder table
        try:
            LibraryFolder_table = Table("library_folder",
                                        metadata,
                                        autoload=True)
        except NoSuchTableError:
            LibraryFolder_table = None
            log.debug("Failed loading table library_folder")
        if LibraryFolder_table is not None:
            # Add the library_id column in 'sample' table
            try:
                if migrate_engine.name != 'sqlite':
                    col = Column("folder_id",
                                 Integer,
                                 ForeignKey("library_folder.id"),
                                 index=True)
                else:
                    col = Column("folder_id", Integer, index=True)
                col.create(Sample_table,
                           index_name='ix_sample_library_folder_id')
                assert col is Sample_table.c.folder_id
            except Exception:
                log.exception(
                    "Adding column 'folder_id' to sample table failed.")
コード例 #13
0
         try:
             Request_table.c.folder_id.drop()
         except Exception, e:
             log.debug(
                 "Deleting column 'folder_id' to request table failed: %s" %
                 (str(e)))
 # sample table
 try:
     Sample_table = Table("sample", metadata, autoload=True)
 except NoSuchTableError:
     Sample_table = None
     log.debug("Failed loading table sample")
 if Sample_table is not None:
     # Add the dataset_files column in 'sample' table
     try:
         col = Column("dataset_files", JSONType())
         col.create(Sample_table)
         assert col is Sample_table.c.dataset_files
     except Exception, e:
         log.debug(
             "Adding column 'dataset_files' to sample table failed: %s" %
             (str(e)))
     # library table
     try:
         Library_table = Table("library", metadata, autoload=True)
     except NoSuchTableError:
         Library_table = None
         log.debug("Failed loading table library")
     if Library_table is not None:
         # Add the library_id column in 'sample' table
         try:
コード例 #14
0
from galaxy.model.migrate.versions.util import (create_table, drop_table)

log = logging.getLogger(__name__)
now = datetime.datetime.utcnow
metadata = MetaData()

FormDefinition_table = Table(
    'form_definition', metadata, Column("id", Integer, primary_key=True),
    Column("create_time", DateTime, default=now),
    Column("update_time", DateTime, default=now, onupdate=now),
    Column("name", TrimmedString(255), nullable=False), Column("desc", TEXT),
    Column("form_definition_current_id",
           Integer,
           ForeignKey("form_definition_current.id", use_alter=True),
           index=True,
           nullable=False), Column("fields", JSONType()))

FormDefinitionCurrent_table = Table(
    'form_definition_current', metadata, Column("id",
                                                Integer,
                                                primary_key=True),
    Column("create_time", DateTime, default=now),
    Column("update_time", DateTime, default=now, onupdate=now),
    Column("latest_form_id",
           Integer,
           ForeignKey("form_definition.id"),
           index=True), Column("deleted", Boolean, index=True, default=False))

FormValues_table = Table(
    'form_values', metadata, Column("id", Integer, primary_key=True),
    Column("create_time", DateTime, default=now),
コード例 #15
0
def upgrade(migrate_engine):
    metadata.bind = migrate_engine
    display_migration_details()
    # Load existing tables
    metadata.reflect()
    # Create the folder_id column
    try:
        Request_table = Table("request", metadata, autoload=True)
    except NoSuchTableError:
        Request_table = None
        log.debug("Failed loading table request")
    if Request_table is not None:
        try:
            col = Column("folder_id", Integer, index=True)
            col.create(Request_table, index_name='ix_request_folder_id')
            assert col is Request_table.c.folder_id
        except Exception as e:
            log.debug("Adding column 'folder_id' to request table failed: %s" %
                      (str(e)))
        try:
            LibraryFolder_table = Table("library_folder",
                                        metadata,
                                        autoload=True)
        except NoSuchTableError:
            LibraryFolder_table = None
            log.debug("Failed loading table library_folder")
        # Add 1 foreign key constraint to the library_folder table
        if migrate_engine.name != 'sqlite' and Request_table is not None and LibraryFolder_table is not None:
            try:
                cons = ForeignKeyConstraint([Request_table.c.folder_id],
                                            [LibraryFolder_table.c.id],
                                            name='request_folder_id_fk')
                # Create the constraint
                cons.create()
            except Exception as e:
                log.debug(
                    "Adding foreign key constraint 'request_folder_id_fk' to table 'library_folder' failed: %s"
                    % (str(e)))
    # Create the type column in form_definition
    try:
        FormDefinition_table = Table("form_definition",
                                     metadata,
                                     autoload=True)
    except NoSuchTableError:
        FormDefinition_table = None
        log.debug("Failed loading table form_definition")
    if FormDefinition_table is not None:
        try:
            col = Column("type", TrimmedString(255), index=True)
            col.create(FormDefinition_table,
                       index_name='ix_form_definition_type')
            assert col is FormDefinition_table.c.type
        except Exception as e:
            log.debug(
                "Adding column 'type' to form_definition table failed: %s" %
                (str(e)))
        try:
            col = Column("layout", JSONType())
            col.create(FormDefinition_table)
            assert col is FormDefinition_table.c.layout
        except Exception as e:
            log.debug(
                "Adding column 'layout' to form_definition table failed: %s" %
                (str(e)))
コード例 #16
0
    Column("name", TEXT), Column("description", TEXT),
    Column("order_id", Integer), Column("item_count", Integer),
    Column("deleted", Boolean, index=True, default=False),
    Column("purged", Boolean, index=True, default=False),
    Column("genome_build", TrimmedString(40)))

LibraryItemInfoTemplateElement_table = Table(
    "library_item_info_template_element", metadata,
    Column("id", Integer, primary_key=True),
    Column("create_time", DateTime, default=now),
    Column("update_time", DateTime, default=now, onupdate=now),
    Column("optional", Boolean, index=True, default=True),
    Column("deleted", Boolean, index=True, default=False),
    Column("name", TEXT), Column("description", TEXT),
    Column("type", TEXT, default='string'), Column("order_id", Integer),
    Column("options", JSONType()),
    Column("library_item_info_template_id", Integer,
           ForeignKey("library_item_info_template.id")))
Index("ix_liite_library_item_info_template_id",
      LibraryItemInfoTemplateElement_table.c.library_item_info_template_id)

LibraryItemInfoTemplate_table = Table(
    "library_item_info_template", metadata,
    Column("id", Integer, primary_key=True),
    Column("create_time", DateTime, default=now),
    Column("update_time", DateTime, default=now, onupdate=now),
    Column("optional", Boolean, index=True, default=True),
    Column("deleted", Boolean, index=True, default=False),
    Column("name", TEXT), Column("description", TEXT),
    Column("item_count", Integer, default=0))
コード例 #17
0
            "Deleting column 'datatx_info' in the 'request_type' table failed: %s"
            % (str(e)))


def downgrade(migrate_engine):
    metadata.bind = migrate_engine
    metadata.reflect()
    try:
        RequestType_table = Table("request_type", metadata, autoload=True)
    except NoSuchTableError, e:
        RequestType_table = None
        log.debug("Failed loading table 'request_type'")
    if RequestType_table is not None:
        # create the 'datatx_info' column
        try:
            col = Column("datatx_info", JSONType())
            col.create(RequestType_table)
            assert col is RequestType_table.c.datatx_info
        except Exception, e:
            log.debug(
                "Creating column 'datatx_info' in the 'request_type' table failed: %s"
                % (str(e)))
        # restore the datatx_info column data in the request_type table with data from
        # the sequencer and the form_values table
        cmd = "SELECT request_type.id, form_values.content "\
              + " FROM request_type, sequencer, form_values "\
              + " WHERE request_type.sequencer_id=sequencer.id AND sequencer.form_values_id=form_values.id "\
              + " ORDER  BY request_type.id ASC"
        result = migrate_engine.execute(cmd)
        for row in result:
            request_type_id = row[0]
コード例 #18
0

def upgrade(migrate_engine):
    metadata.bind = migrate_engine
    print __doc__
    metadata.reflect()
    try:
        Request_table = Table("request", metadata, autoload=True)
    except NoSuchTableError, e:
        Request_table = None
        log.debug("Failed loading table 'request'")

    if Request_table is not None:
        # create the column again as JSONType
        try:
            col = Column("notification", JSONType())
            col.create(Request_table)
            assert col is Request_table.c.notification
        except Exception, e:
            log.debug(
                "Creating column 'notification' in the 'request' table failed: %s"
                % (str(e)))

        cmd = "SELECT id, user_id, notify FROM request"
        result = migrate_engine.execute(cmd)
        for r in result:
            id = int(r[0])
            notify_new = dict(email=[], sample_states=[], body='', subject='')
            cmd = "UPDATE request SET notification='%s' WHERE id=%i" % (
                dumps(notify_new), id)
            migrate_engine.execute(cmd)
コード例 #19
0
    try:
        FormDefinition_table = Table("form_definition",
                                     metadata,
                                     autoload=True)
    except NoSuchTableError:
        FormDefinition_table = None
        log.debug("Failed loading table form_definition")
    if FormDefinition_table is not None:
        try:
            col = Column("type", TrimmedString(255), index=True)
            col.create(FormDefinition_table,
                       index_name='ix_form_definition_type')
            assert col is FormDefinition_table.c.type
        except Exception, e:
            log.debug(
                "Adding column 'type' to form_definition table failed: %s" %
                (str(e)))
        try:
            col = Column("layout", JSONType())
            col.create(FormDefinition_table)
            assert col is FormDefinition_table.c.layout
        except Exception, e:
            log.debug(
                "Adding column 'layout' to form_definition table failed: %s" %
                (str(e)))


def downgrade(migrate_engine):
    metadata.bind = migrate_engine
    pass
コード例 #20
0
    create_table,
    drop_table
)

log = logging.getLogger(__name__)
now = datetime.datetime.utcnow
metadata = MetaData()

FormDefinition_table = Table('form_definition', metadata,
                             Column("id", Integer, primary_key=True),
                             Column("create_time", DateTime, default=now),
                             Column("update_time", DateTime, default=now, onupdate=now),
                             Column("name", TrimmedString(255), nullable=False),
                             Column("desc", TEXT),
                             Column("form_definition_current_id", Integer, ForeignKey("form_definition_current.id", use_alter=True), index=True, nullable=False),
                             Column("fields", JSONType()))

FormDefinitionCurrent_table = Table('form_definition_current', metadata,
                                    Column("id", Integer, primary_key=True),
                                    Column("create_time", DateTime, default=now),
                                    Column("update_time", DateTime, default=now, onupdate=now),
                                    Column("latest_form_id", Integer, ForeignKey("form_definition.id"), index=True),
                                    Column("deleted", Boolean, index=True, default=False))

FormValues_table = Table('form_values', metadata,
                         Column("id", Integer, primary_key=True),
                         Column("create_time", DateTime, default=now),
                         Column("update_time", DateTime, default=now, onupdate=now),
                         Column("form_definition_id", Integer, ForeignKey("form_definition.id"), index=True),
                         Column("content", JSONType()))
コード例 #21
0
DynamicTool_table = Table(
    "dynamic_tool",
    metadata,
    Column("id", Integer, primary_key=True),
    Column("uuid", UUIDType()),
    Column("create_time", DateTime, default=now),
    Column("update_time", DateTime, default=now, onupdate=now),
    Column("tool_id", Unicode(255)),
    Column("tool_version", Unicode(255)),
    Column("tool_format", Unicode(255)),
    Column("tool_path", Unicode(255)),
    Column("tool_directory", Unicode(255)),
    Column("hidden", Boolean),
    Column("active", Boolean),
    Column("value", JSONType()),
)

TABLES = [
    DynamicTool_table,
]


def upgrade(migrate_engine):
    print(__doc__)
    metadata.bind = migrate_engine
    metadata.reflect()

    for table in TABLES:
        create_table(table)