Python sqlalchemy 模块,Column() 实例源码

我们从Python开源项目中,提取了以下50个代码示例,用于说明如何使用sqlalchemy.Column()

项目:zipline-chinese    作者:zhanghan1990    | 项目源码 | 文件源码
def _equities_table_schema(metadata):
    # NOTE: When modifying this schema, update the ASSET_DB_VERSION value
    return sa.Table(
        'equities',
        metadata,
        sa.Column(
            'sid',
            sa.Integer,
            unique=True,
            nullable=False,
            primary_key=True,
        ),
        sa.Column('symbol', sa.Text),
        sa.Column('company_symbol', sa.Text, index=True),
        sa.Column('share_class_symbol', sa.Text),
        sa.Column('fuzzy_symbol', sa.Text, index=True),
        sa.Column('asset_name', sa.Text),
        sa.Column('start_date', sa.Integer, default=0, nullable=False),
        sa.Column('end_date', sa.Integer, nullable=False),
        sa.Column('first_traded', sa.Integer, nullable=False),
        sa.Column('auto_close_date', sa.Integer),
        sa.Column('exchange', sa.Text),
    )
项目:eventor    作者:Acrisel    | 项目源码 | 文件源码
def info_table(base):
    class Info(base):
        __tablename__ = 'Info'

        id_ = Column(Integer, Sequence('trigger_id_seq'), primary_key=True)
        run_id=Column(String, nullable=False)
        name=Column(String, nullable=False)
        value=Column(String, nullable=True)

        __table_args__ = (
                UniqueConstraint('run_id', 'name'),
                )

        def __repr__(self):
            return "<Info(run_id='%s', name='%s', value='%s')>" % (self.run_id, self.name, self.value)

    return Info
项目:podigger    作者:perna    | 项目源码 | 文件源码
def upgrade():
    ### commands auto generated by Alembic - please adjust! ###
    op.create_table('topic_suggestion',
    sa.Column('id', sa.Integer(), nullable=False),
    sa.Column('created_at', sa.DateTime(), nullable=True),
    sa.Column('updated_at', sa.DateTime(), nullable=True),
    sa.Column('title', sa.String(), nullable=False),
    sa.Column('description', sa.Text(), nullable=True),
    sa.Column('is_recorded', sa.Boolean(), nullable=False),
    sa.Column('podcast_id', sa.Integer(), nullable=True),
    sa.ForeignKeyConstraint(['podcast_id'], ['podcast.id'], ),
    sa.PrimaryKeyConstraint('id')
    )
    op.create_index(op.f('ix_topic_suggestion_id'), 'topic_suggestion', ['id'], unique=False)
    op.create_index(op.f('ix_topic_suggestion_title'), 'topic_suggestion', ['title'], unique=False)
    op.create_index(op.f('ix_episode_id'), 'episode', ['id'], unique=False)
    op.create_index(op.f('ix_podcast_id'), 'podcast', ['id'], unique=False)
    op.create_index(op.f('ix_popular_term_id'), 'popular_term', ['id'], unique=False)
    op.create_index(op.f('ix_tag_id'), 'tag', ['id'], unique=False)
    ### end Alembic commands ###
项目:zipline-chinese    作者:zhanghan1990    | 项目源码 | 文件源码
def _futures_root_symbols_schema(metadata):
    # NOTE: When modifying this schema, update the ASSET_DB_VERSION value
    return sa.Table(
        'futures_root_symbols',
        metadata,
        sa.Column(
            'root_symbol',
            sa.Text,
            unique=True,
            nullable=False,
            primary_key=True,
        ),
        sa.Column('root_symbol_id', sa.Integer),
        sa.Column('sector', sa.Text),
        sa.Column('description', sa.Text),
        sa.Column(
            'exchange',
            sa.Text,
            sa.ForeignKey('futures_exchanges.exchange'),
        ),
    )
项目:Flask_Blog    作者:sugarguo    | 项目源码 | 文件源码
def props(self):
        props = []
        for attr in self.attrs:
            if isinstance(attr, str):
                prop = self.parent.get_property(
                    attr, _configure_mappers=False)
            elif isinstance(attr, schema.Column):
                prop = self.parent._columntoproperty[attr]
            elif isinstance(attr, attributes.InstrumentedAttribute):
                prop = attr.property
            else:
                raise sa_exc.ArgumentError(
                    "Composite expects Column objects or mapped "
                    "attributes/attribute names as arguments, got: %r"
                    % (attr,))
            props.append(prop)
        return props
项目:FRG-Crowdsourcing    作者:97amarnathk    | 项目源码 | 文件源码
def upgrade():
    op.create_table(
        'project_stats',
        sa.Column('id', sa.Integer, primary_key=True),
        sa.Column('project_id', sa.Integer, sa.ForeignKey('project.id',
                                                          ondelete='CASCADE')),
        sa.Column('n_tasks', sa.Integer, default=0),
        sa.Column('n_task_runs', sa.Integer, default=0),
        sa.Column('n_results', sa.Integer, default=0),
        sa.Column('n_volunteers', sa.Integer, default=0),
        sa.Column('n_completed_tasks', sa.Integer, default=0),
        sa.Column('overall_progress', sa.Integer, default=0),
        sa.Column('average_time', sa.Float, default=0),
        sa.Column('n_blogposts', sa.Integer, default=0),
        sa.Column('last_activity', sa.Text, default=make_timestamp),
        sa.Column('info', JSON, nullable=False)
    )
项目:cyborg    作者:openstack    | 项目源码 | 文件源码
def upgrade():
    op.create_table(
        'accelerators',
        sa.Column('created_at', sa.DateTime(), nullable=True),
        sa.Column('updated_at', sa.DateTime(), nullable=True),
        sa.Column('id', sa.Integer(), nullable=False),
        sa.Column('uuid', sa.String(length=36), nullable=False),
        sa.Column('name', sa.String(length=255), nullable=False),
        sa.Column('description', sa.Text(), nullable=True),
        sa.Column('project_id', sa.String(length=36), nullable=True),
        sa.Column('user_id', sa.String(length=36), nullable=True),
        sa.Column('device_type', sa.Text(), nullable=False),
        sa.Column('acc_type', sa.Text(), nullable=False),
        sa.Column('acc_capability', sa.Text(), nullable=False),
        sa.Column('vendor_id', sa.Text(), nullable=False),
        sa.Column('product_id', sa.Text(), nullable=False),
        sa.Column('remotable', sa.Integer(), nullable=False),
        sa.PrimaryKeyConstraint('id'),
        mysql_ENGINE='InnoDB',
        mysql_DEFAULT_CHARSET='UTF8'
    )
项目:tuning-box    作者:openstack    | 项目源码 | 文件源码
def downgrade():
    table_prefix = context.config.get_main_option('table_prefix')
    table_name = table_prefix + 'environment_hierarchy_level_value'
    with op.batch_alter_table(table_name) as batch:
        batch.drop_constraint(
            table_name + '_level_id_value_unique',
            type_='unique'
        )

        batch.drop_constraint(
            table_name + '_level_id_fkey',
            type_='foreignkey'
        )
        batch.create_foreign_key(
            table_name + '_level_id_fkey',
            table_prefix + 'environment_hierarchy_level',
            ['level_id'], ['id']
        )

        batch.add_column(sa.Column('parent_id', sa.Integer(), nullable=True))
        batch.create_foreign_key(
            table_name + '_parent_id_fkey',
            table_name,
            ['parent_id'], ['id']
        )
项目:bit    作者:codesmart-co    | 项目源码 | 文件源码
def upgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    op.create_table('bit_facebook_daily_ad_insights_impression_device',
    sa.Column('id', sa.Integer(), nullable=False),
    sa.Column('account_id', sa.String(length=255), nullable=True),
    sa.Column('campaign_id', sa.String(length=255), nullable=True),
    sa.Column('adset_id', sa.String(length=255), nullable=True),
    sa.Column('campaign_name', sa.String(length=255), nullable=True),
    sa.Column('spend', sa.Numeric(), nullable=True),
    sa.Column('cost_per_unique_click', sa.Numeric(), nullable=True),
    sa.Column('unique_clicks', sa.Integer(), nullable=True),
    sa.Column('unique_impressions', sa.Integer(), nullable=True),
    sa.Column('unique_social_clicks', sa.Integer(), nullable=True),
    sa.Column('unique_social_impressions', sa.Integer(), nullable=True),
    sa.Column('website_clicks', sa.Integer(), nullable=True),
    sa.Column('date_start', sa.DateTime(), nullable=True),
    sa.Column('date_stop', sa.DateTime(), nullable=True),
    sa.Column('impression_device', sa.String(length=255), nullable=True),
    sa.Column('ad_id', sa.Integer(), nullable=True),
    sa.ForeignKeyConstraint(['ad_id'], ['bit_facebook_ad.id'], ),
    sa.PrimaryKeyConstraint('id')
    )
    op.create_index(op.f('ix_bit_facebook_daily_ad_insights_impression_device_impression_device'), 'bit_facebook_daily_ad_insights_impression_device', ['impression_device'], unique=False)
    # ### end Alembic commands ###
项目:sqlalchemy_bulk_lazy_loader    作者:operator    | 项目源码 | 文件源码
def _get_join_col_from_criterion(self, criterion, reverse=False):
        """
        Criterion is the filter clause used by the LazyLoader base class. It's of the form `:param = Model.column_id`
        This method extracts the Model.column_id so we can make our own `Model.column_id IN :param` bulk query
        """

        if isinstance(criterion, BooleanClauseList):
            for clause in criterion.clauses:
                col = self._get_join_col_from_criterion(clause)
                if col is not None:
                    return col
        elif isinstance(criterion, BinaryExpression):
            if isinstance(criterion.left, Column) and isinstance(criterion.right, BindParameter):
                return criterion.left
            elif isinstance(criterion.right, Column) and isinstance(criterion.left, BindParameter):
                return criterion.right
        return None
项目:sqlalchemy-media    作者:pylover    | 项目源码 | 文件源码
def test_delete_orphan(self):

        class Person(self.Base):
            __tablename__ = 'person'
            id = Column(Integer, primary_key=True)
            cv = Column(File.as_mutable(Json), nullable=True)

        session = self.create_all_and_get_session()
        person1 = Person()
        self.assertIsNone(person1.cv)

        with StoreManager(session, delete_orphan=True):
            # First file before commit
            person1.cv = File.create_from(BytesIO(b'Simple text.'), content_type='text/plain', extension='.txt')
            self.assertIsInstance(person1.cv, File)
            first_filename = join(self.temp_path, person1.cv.path)
            self.assertTrue(exists(first_filename))
            person1.cv = File.create_from(BytesIO(b'Second simple text.'))
            second_filename = join(self.temp_path, person1.cv.path)
            self.assertTrue(exists(first_filename))
            self.assertTrue(exists(second_filename))
            session.add(person1)
            session.commit()
            self.assertFalse(exists(first_filename))
            self.assertTrue(exists(second_filename))
项目:sqlalchemy-media    作者:pylover    | 项目源码 | 文件源码
def test_without_delete_orphan(self):

        class Person(self.Base):
            __tablename__ = 'person'
            id = Column(Integer, primary_key=True)
            cv = Column(File.as_mutable(Json), nullable=True)

        session = self.create_all_and_get_session()
        person1 = Person()

        with StoreManager(session):

            # First file before commit
            person1.cv = File.create_from(BytesIO(b'Simple text.'), content_type='text/plain', extension='.txt')
            first_filename = join(self.temp_path, person1.cv.path)
            person1.cv = File.create_from(BytesIO(b'Second simple text.'))
            second_filename = join(self.temp_path, person1.cv.path)
            session.add(person1)
            session.commit()
            self.assertTrue(exists(first_filename))
            self.assertTrue(exists(second_filename))
项目:sqlalchemy-media    作者:pylover    | 项目源码 | 文件源码
def test_delete_orphan_image(self):
        """
        https://github.com/pylover/sqlalchemy-media/issues/81
        """
        class Person(self.Base):
            __tablename__ = 'person'
            id = Column(Integer, primary_key=True)
            pic = Column(Image.as_mutable(Json), nullable=True)

        session = self.create_all_and_get_session()

        with StoreManager(session, delete_orphan=True):
            person1 = Person()
            person1.pic = Image.create_from(self.cat_jpeg)
            first_filename = join(self.temp_path, person1.pic.path)
            session.commit()
            self.assertTrue(exists(first_filename))

            person1.pic = Image.create_from(self.dog_jpeg)
            session.commit()
            self.assertFalse(exists(first_filename))
项目:sqlalchemy-media    作者:pylover    | 项目源码 | 文件源码
def test_decorator(self):

        class Person(self.Base):
            __tablename__ = 'person'
            id = Column(Integer, primary_key=True)
            image = Column(Image.as_mutable(Json), nullable=True)

        session = self.create_all_and_get_session()

        person1 = Person()
        self.assertIsNone(person1.image)

        @store_manager(session)
        def add_image():
            person1.image = Image.create_from(self.dog_jpeg)
            self.assertEqual(person1.image.content_type, 'image/jpeg')
            self.assertEqual(person1.image.extension, '.jpg')
            self.assertTrue(exists(join(self.temp_path, person1.image.path)))

            person1.image = Image.create_from(self.dog_png)
            self.assertEqual(person1.image.content_type, 'image/png')
            self.assertTrue(exists(join(self.temp_path, person1.image.path)))

        add_image()
项目:sqlalchemy-media    作者:pylover    | 项目源码 | 文件源码
def test_file_size_limit(self):

        class LimitedFile(File):
            __min_length__ = 20
            __max_length__ = 30

        class Person(self.Base):
            __tablename__ = 'person'
            id = Column(Integer, primary_key=True)
            cv = Column(LimitedFile.as_mutable(Json), nullable=True)

        session = self.create_all_and_get_session()

        person1 = Person()
        person1.cv = LimitedFile()

        with StoreManager(session):

            # MaximumLengthIsReachedError, MinimumLengthIsNotReachedError
            self.assertRaises(MinimumLengthIsNotReachedError, person1.cv.attach, BytesIO(b'less than 20 chars!'))
            self.assertRaises(MaximumLengthIsReachedError, person1.cv.attach,
                              BytesIO(b'more than 30 chars!............'))
项目:sqlalchemy-media    作者:pylover    | 项目源码 | 文件源码
def test_attribute_type_assertion(self):
        class MyAttachmentType(File):
            pass

        class Person(self.Base):
            __tablename__ = 'person'
            id = Column(Integer, primary_key=True)
            cv = Column(MyAttachmentType.as_mutable(Json), nullable=True)

        person1 = Person()

        def set_invalid_type():
            person1.cv = list()

        def set_invalid_type_via_constructor():
            Person(cv=67)

        self.assertRaises(TypeError, set_invalid_type)
        self.assertRaises(TypeError, set_invalid_type_via_constructor)
项目:sqlalchemy-media    作者:pylover    | 项目源码 | 文件源码
def test_attribute_type_coercion(self):

        class MyAttachmentType(File):
            __auto_coercion__ = True
            pass

        class Person(self.Base):
            __tablename__ = 'person'
            id = Column(Integer, primary_key=True)
            cv = Column(MyAttachmentType.as_mutable(Json), nullable=True)

        session = self.create_all_and_get_session()
        with StoreManager(session):
            person1 = Person()
            person1.cv = BytesIO(b'Simple text')
            self.assertIsInstance(person1.cv, MyAttachmentType)

            person2 = Person(cv=BytesIO(b'Simple text'))
            self.assertIsInstance(person2.cv, MyAttachmentType)
            session.add(person2)
            session.commit()
项目:sqlalchemy-media    作者:pylover    | 项目源码 | 文件源码
def test_overwrite(self):
        class Person(self.Base):
            __tablename__ = 'person'
            id = Column(Integer, primary_key=True)
            cv = Column(File.as_mutable(Json), nullable=True)

        session = self.create_all_and_get_session()
        person1 = Person(cv=File())
        self.assertIsInstance(person1.cv, File)
        with StoreManager(session):
            person1.cv.attach(BytesIO(b'Simple text'))
            cv_filename = join(self.temp_path, person1.cv.path)
            self.assertTrue(exists(cv_filename))
            session.add(person1)
            session.commit()

            # Now overwriting the file
            person1 = session.query(Person).filter(Person.id == person1.id).one()
            person1.cv.attach(BytesIO(b'Another simple text'), overwrite=True)
            self.assertTrue(exists(cv_filename))
            session.commit()
            self.assertTrue(exists(cv_filename))
项目:sqlalchemy-media    作者:pylover    | 项目源码 | 文件源码
def test_content_type_validator(self):

        class PDFFile(File):
            __pre_processors__ = [
                MagicAnalyzer(),
                ContentTypeValidator(['application/pdf', 'image/jpeg'])
            ]

        class Person(self.Base):
            __tablename__ = 'person'
            id = Column(Integer, primary_key=True)
            cv = Column(PDFFile.as_mutable(Json), nullable=True)

        session = self.create_all_and_get_session()
        person1 = Person(cv=PDFFile())
        with StoreManager(session):
            self.assertIsNotNone(person1.cv.attach(self.cat_jpeg))
            self.assertRaises(ContentTypeValidationError, person1.cv.attach, BytesIO(b'Simple text'))
项目:sqlalchemy-media    作者:pylover    | 项目源码 | 文件源码
def test_image(self):

        class Person(self.Base):
            __tablename__ = 'person'
            id = Column(Integer, primary_key=True)
            image = Column(Image.as_mutable(Json), nullable=True)

        session = self.create_all_and_get_session()

        # person1 = Person(name='person1')
        person1 = Person()
        self.assertIsNone(person1.image)

        with StoreManager(session):
            person1.image = Image.create_from(self.dog_jpeg)
            self.assertEqual(person1.image.content_type, 'image/jpeg')
            self.assertEqual(person1.image.extension, '.jpg')
            self.assertTrue(exists(join(self.temp_path, person1.image.path)))

            person1.image = Image.create_from(self.dog_png)
            self.assertEqual(person1.image.content_type, 'image/png')
            self.assertTrue(exists(join(self.temp_path, person1.image.path)))
项目:sqlalchemy-media    作者:pylover    | 项目源码 | 文件源码
def test_pre_process(self):

        class Banner(Image):
            __pre_processors__ = ImageProcessor(fmt='jpeg', width=300)

        class Person(self.Base):
            __tablename__ = 'person'
            id = Column(Integer, primary_key=True)
            image = Column(Banner.as_mutable(Json), nullable=True)

        session = self.create_all_and_get_session()

        # person1 = Person(name='person1')
        person1 = Person()
        self.assertIsNone(person1.image)

        with StoreManager(session):
            person1.image = Banner.create_from(self.cat_png)
            self.assertEqual(person1.image.content_type, 'image/jpeg')
项目:anormbookmarker    作者:jakeogh    | 项目源码 | 文件源码
def __new__(cls, mapper_to_bookmark):
        class_attr = {}
        class_attr['id'] = Column(Integer, primary_key=True)
        class_attr['tagwords'] = relationship("TagWord", backref='tag') # list of TagWord instances
        class_attr['parents'] = relationship('Tag',
                                             secondary=tag_relationship,
                                             primaryjoin=tag_relationship.c.tag_id == class_attr['id'],
                                             secondaryjoin=tag_relationship.c.tag_parent_id == class_attr['id'],
                                             backref="children")
        target_class_name = mapper_to_bookmark.__name__
        target_name = target_class_name.lower().split('.')[-1] # 'filename' usually

        class_attr['target_class_name'] = target_class_name
        class_attr['target_name'] = target_name

        class_attr['__init__'] = init
        class_attr['__repr__'] = display
        class_attr['construct'] = construct         # @classmethod
        class_attr['tag'] = build_tag               # @property
        class_attr[target_name+'s'] = tag_targets   # @hybrid_property
        class_attr['words'] = words                 # @hybrid_property
        return type('Tag', (BASE,), class_attr)
项目:eventor    作者:Acrisel    | 项目源码 | 文件源码
def trigger_table(base):
    class Trigger(base):
        __tablename__ = 'Trigger'

        id_ = Column(Integer, Sequence('trigger_id_seq'), primary_key=True)
        run_id = Column(String, nullable=False, default='')
        event_id = Column(String, nullable=False)
        sequence = Column(Integer, nullable=False)
        recovery = Column(Integer, nullable=False, default=0)
        created = Column(DateTime(), default=datetime.utcnow) 
        acted = Column(DateTime(), nullable=True) 

        def __repr__(self):
            return "<Trigger(id='%s', run_id='%s', event_id='%s', sequence='%s', recovery='%s', created='%s', acted='%s')>" % (
                self.id_, self.run_id, self.event_id, self.sequence, self.recovery, self.created, self.acted)

    return Trigger
项目:eventor    作者:Acrisel    | 项目源码 | 文件源码
def task_table(base):
    class Task(base):
        __tablename__ = 'Task'

        id_ = Column(Integer, Sequence('task_id_seq'), primary_key=True)
        run_id = Column(String, default='')
        step_id = Column(String,)
        sequence = Column(Integer,)
        recovery = Column(Integer, nullable=False)
        pid = Column(Integer, nullable=True)
        status = Column(SQLEnum(TaskStatus), ) 
        result = Column(PickleType() , nullable=True,)
        created = Column(DateTime(), default=datetime.utcnow) 
        updated = Column(DateTime(), nullable=True, ) 

        __table_args__ = (
                UniqueConstraint('run_id', 'step_id', 'sequence', 'recovery'),
                )

        def __repr__(self):
            return "<Task(id='%s', run_id='%s', step_id='%s', sequence='%s', recovery='%s', pid='%s', status='%s', created='%s', updated='%s')>" % (
                self.id_, self.run_id, self.step_id, self.sequence, self.recovery, self.pid, self.status, self.created, self.updated)

    return Task
项目:eventor    作者:Acrisel    | 项目源码 | 文件源码
def delay_table(base):
    class Delay(base):
        __tablename__ = 'Delay'

        id_=Column(Integer, Sequence('delay_id_seq'), primary_key=True)
        run_id = Column(String, default='')
        delay_id = Column(String,)
        sequence = Column(Integer,)
        recovery = Column(Integer,)
        seconds = Column(BigInteger, nullable=True)
        active = Column(Boolean, default=False)
        activated = Column(DateTime(), nullable=True,) 
        updated = Column(DateTime(), default=datetime.utcnow) 

        __table_args__ = (
                UniqueConstraint('run_id', 'delay_id', 'sequence', 'recovery'),
                )

        def __repr__(self):
            return "<Delay(id='%s', run_id='%s', delay_id='%s', delay='%s', active='%s', activated='%s')>" % (
                self.id_, self.run_id, self.delay_id, self.seconds, self.active, self.activated)

    return Delay
项目:Leics    作者:LeicsFrameWork    | 项目源码 | 文件源码
def upgrade():
    ### commands auto generated by Alembic - please adjust! ###
    op.create_table('roles',
    sa.Column('id', sa.Integer(), nullable=False),
    sa.Column('name', sa.String(length=64), nullable=True),
    sa.Column('default', sa.Boolean(), nullable=True),
    sa.Column('permissions', sa.Integer(), nullable=True),
    sa.PrimaryKeyConstraint('id'),
    sa.UniqueConstraint('name')
    )
    op.create_index(op.f('ix_roles_default'), 'roles', ['default'], unique=False)
    op.create_table('users',
    sa.Column('id', sa.Integer(), nullable=False),
    sa.Column('username', sa.String(length=164), nullable=True),
    sa.Column('email', sa.String(length=164), nullable=True),
    sa.Column('role_id', sa.Integer(), nullable=True),
    sa.Column('password_hash', sa.String(length=164), nullable=True),
    sa.ForeignKeyConstraint(['role_id'], ['roles.id'], ),
    sa.PrimaryKeyConstraint('id')
    )
    op.create_index(op.f('ix_users_username'), 'users', ['username'], unique=True)
    ### end Alembic commands ###
项目:QXSConsolas    作者:qxsch    | 项目源码 | 文件源码
def props(self):
        props = []
        for attr in self.attrs:
            if isinstance(attr, str):
                prop = self.parent.get_property(
                    attr, _configure_mappers=False)
            elif isinstance(attr, schema.Column):
                prop = self.parent._columntoproperty[attr]
            elif isinstance(attr, attributes.InstrumentedAttribute):
                prop = attr.property
            else:
                raise sa_exc.ArgumentError(
                    "Composite expects Column objects or mapped "
                    "attributes/attribute names as arguments, got: %r"
                    % (attr,))
            props.append(prop)
        return props
项目:podigger    作者:perna    | 项目源码 | 文件源码
def upgrade():
    ### commands auto generated by Alembic - please adjust! ###
    op.create_table('episode',
    sa.Column('id', sa.Integer(), nullable=False),
    sa.Column('title', sa.String(), nullable=False),
    sa.Column('link', sa.String(), nullable=False),
    sa.Column('description', sa.Text(), nullable=True),
    sa.Column('published', sa.DateTime(), nullable=True),
    sa.Column('enclosure', sa.String(), nullable=True),
    sa.Column('created_at', sa.DateTime(), nullable=True),
    sa.Column('updated_at', sa.DateTime(), nullable=True),
    sa.Column('podcast_id', sa.Integer(), nullable=True),
    sa.ForeignKeyConstraint(['podcast_id'], ['podcast.id'], ),
    sa.PrimaryKeyConstraint('id'),
    sa.UniqueConstraint('link'),
    sa.UniqueConstraint('title')
    )
    op.create_index(op.f('ix_podcast_feed'), 'podcast', ['feed'], unique=True)
    op.create_index(op.f('ix_podcast_name'), 'podcast', ['name'], unique=True)
    ### end Alembic commands ###
项目:podigger    作者:perna    | 项目源码 | 文件源码
def upgrade():
    ### commands auto generated by Alembic - please adjust! ###
    op.create_table('role',
    sa.Column('id', sa.Integer(), nullable=False),
    sa.Column('name', sa.String(length=80), nullable=True),
    sa.Column('description', sa.String(length=255), nullable=True),
    sa.PrimaryKeyConstraint('id'),
    sa.UniqueConstraint('name')
    )
    op.create_table('user',
    sa.Column('id', sa.Integer(), nullable=False),
    sa.Column('email', sa.String(length=255), nullable=True),
    sa.Column('active', sa.Boolean(), nullable=True),
    sa.Column('confirmed_at', sa.DateTime(), nullable=True),
    sa.PrimaryKeyConstraint('id'),
    sa.UniqueConstraint('email')
    )
    op.create_table('roles_users',
    sa.Column('user_id', sa.Integer(), nullable=True),
    sa.Column('role_id', sa.Integer(), nullable=True),
    sa.ForeignKeyConstraint(['role_id'], ['role.id'], ),
    sa.ForeignKeyConstraint(['user_id'], ['user.id'], )
    )
    ### end Alembic commands ###
项目:fuel-nailgun-extension-iac    作者:openstack    | 项目源码 | 文件源码
def upgrade():
    table_prefix = context.config.get_main_option('table_prefix')
    op.create_table(
        table_prefix + 'repos',
        sa.Column('id', sa.Integer(), nullable=False, primary_key=True),
        sa.Column('repo_name', sa.Unicode(100), nullable=False),
        sa.Column('env_id', sa.Integer(), nullable=False),
        sa.Column('git_url', sa.String(255),
                  server_default='', nullable=False),
        sa.Column('ref', sa.String(255),
                  server_default='', nullable=False),
        sa.Column('user_key', sa.String(255),
                  server_default='', nullable=False),
        sa.UniqueConstraint('env_id', name='_env_id_unique'))
项目:fuel-nailgun-extension-iac    作者:openstack    | 项目源码 | 文件源码
def upgrade():
    table_prefix = context.config.get_main_option('table_prefix')
    op.add_column(
        table_prefix + 'repos',
        sa.Column('manage_master', sa.Boolean(), nullable=True)
    )
项目:fuel-nailgun-extension-iac    作者:openstack    | 项目源码 | 文件源码
def upgrade():
    table_prefix = context.config.get_main_option('table_prefix')
    op.add_column(
        table_prefix + 'changes_whitelist',
        sa.Column('fuel_task', sa.String, server_default='', nullable=False)
    )
项目:fuel-nailgun-extension-iac    作者:openstack    | 项目源码 | 文件源码
def upgrade():
    table_prefix = context.config.get_main_option('table_prefix')
    op.create_table(
        table_prefix + 'changes_whitelist',
        sa.Column('id', sa.Integer(), nullable=False, primary_key=True),
        sa.Column('env_id', sa.Integer(), nullable=False),
        sa.Column('rule', sa.String(255),
                  server_default='', nullable=False)
    )
项目:zipline-chinese    作者:zhanghan1990    | 项目源码 | 文件源码
def _futures_exchanges_schema(metadata):
    # NOTE: When modifying this schema, update the ASSET_DB_VERSION value
    return sa.Table(
        'futures_exchanges',
        metadata,
        sa.Column(
            'exchange',
            sa.Text,
            unique=True,
            nullable=False,
            primary_key=True,
        ),
        sa.Column('timezone', sa.Text),
    )
项目:zipline-chinese    作者:zhanghan1990    | 项目源码 | 文件源码
def _futures_contracts_schema(metadata):
    # NOTE: When modifying this schema, update the ASSET_DB_VERSION value
    return sa.Table(
        'futures_contracts',
        metadata,
        sa.Column(
            'sid',
            sa.Integer,
            unique=True,
            nullable=False,
            primary_key=True,
        ),
        sa.Column('symbol', sa.Text, unique=True, index=True),
        sa.Column(
            'root_symbol',
            sa.Text,
            sa.ForeignKey('futures_root_symbols.root_symbol'),
            index=True
        ),
        sa.Column('asset_name', sa.Text),
        sa.Column('start_date', sa.Integer, default=0, nullable=False),
        sa.Column('end_date', sa.Integer, nullable=False),
        sa.Column('first_traded', sa.Integer, nullable=False),
        sa.Column(
            'exchange',
            sa.Text,
            sa.ForeignKey('futures_exchanges.exchange'),
        ),
        sa.Column('notice_date', sa.Integer, nullable=False),
        sa.Column('expiration_date', sa.Integer, nullable=False),
        sa.Column('auto_close_date', sa.Integer, nullable=False),
        sa.Column('multiplier', sa.Float),
        sa.Column('tick_size', sa.Float),
    )
项目:zipline-chinese    作者:zhanghan1990    | 项目源码 | 文件源码
def _asset_router_schema(metadata):
    # NOTE: When modifying this schema, update the ASSET_DB_VERSION value
    return sa.Table(
        'asset_router',
        metadata,
        sa.Column(
            'sid',
            sa.Integer,
            unique=True,
            nullable=False,
            primary_key=True),
        sa.Column('asset_type', sa.Text),
    )
项目:zlktqa    作者:NunchakusHuang    | 项目源码 | 文件源码
def upgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    op.add_column('answers', sa.Column('create_time', sa.DateTime(), nullable=True))
    # ### end Alembic commands ###
项目:zlktqa    作者:NunchakusHuang    | 项目源码 | 文件源码
def upgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    op.create_table('users',
    sa.Column('id', sa.String(length=100), nullable=False),
    sa.Column('username', sa.String(length=100), nullable=False),
    sa.Column('telephone', sa.String(length=11), nullable=False),
    sa.Column('_password', sa.String(length=100), nullable=False),
    sa.PrimaryKeyConstraint('id')
    )
    op.create_table('questions',
    sa.Column('id', sa.Integer(), nullable=False),
    sa.Column('title', sa.String(length=100), nullable=False),
    sa.Column('content', sa.Text(), nullable=False),
    sa.Column('author_id', sa.String(length=100), nullable=True),
    sa.ForeignKeyConstraint(['author_id'], ['users.id'], ),
    sa.PrimaryKeyConstraint('id')
    )
    op.create_table('answers',
    sa.Column('id', sa.Integer(), nullable=False),
    sa.Column('content', sa.Text(), nullable=False),
    sa.Column('question_id', sa.Integer(), nullable=True),
    sa.Column('author_id', sa.String(length=100), nullable=True),
    sa.ForeignKeyConstraint(['author_id'], ['users.id'], ),
    sa.ForeignKeyConstraint(['question_id'], ['questions.id'], ),
    sa.PrimaryKeyConstraint('id')
    )
    # ### end Alembic commands ###
项目:zlktqa    作者:NunchakusHuang    | 项目源码 | 文件源码
def upgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    op.add_column('questions', sa.Column('create_time', sa.DateTime(), nullable=True))
    # ### end Alembic commands ###
项目:tasker    作者:DominikPott    | 项目源码 | 文件源码
def task_association_id(cls):
        return Column(Integer, ForeignKey('task_association.id'))
项目:Flask_Blog    作者:sugarguo    | 项目源码 | 文件源码
def columns(self):
        return [a for a in self.attrs if isinstance(a, schema.Column)]
项目:Flask_Blog    作者:sugarguo    | 项目源码 | 文件源码
def _make_table(db):
    def _make_table(*args, **kwargs):
        if len(args) > 1 and isinstance(args[1], db.Column):
            args = (args[0], db.metadata) + args[1:]
        info = kwargs.pop('info', None) or {}
        info.setdefault('bind_key', None)
        kwargs['info'] = info
        return sqlalchemy.Table(*args, **kwargs)
    return _make_table
项目:Flask_Blog    作者:sugarguo    | 项目源码 | 文件源码
def _should_set_tablename(bases, d):
    """Check what values are set by a class and its bases to determine if a
    tablename should be automatically generated.

    The class and its bases are checked in order of precedence: the class
    itself then each base in the order they were given at class definition.

    Abstract classes do not generate a tablename, although they may have set
    or inherited a tablename elsewhere.

    If a class defines a tablename or table, a new one will not be generated.
    Otherwise, if the class defines a primary key, a new name will be generated.

    This supports:

    * Joined table inheritance without explicitly naming sub-models.
    * Single table inheritance.
    * Inheriting from mixins or abstract models.

    :param bases: base classes of new class
    :param d: new class dict
    :return: True if tablename should be set
    """

    if '__tablename__' in d or '__table__' in d or '__abstract__' in d:
        return False

    if any(v.primary_key for v in itervalues(d) if isinstance(v, sqlalchemy.Column)):
        return True

    for base in bases:
        if hasattr(base, '__tablename__') or hasattr(base, '__table__'):
            return False

        for name in dir(base):
            attr = getattr(base, name)

            if isinstance(attr, sqlalchemy.Column) and attr.primary_key:
                return True
项目:BookCloud    作者:livro-aberto    | 项目源码 | 文件源码
def upgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    op.add_column('named_tag', sa.Column('file_regexp', sa.String(length=200), nullable=True))
    # ### end Alembic commands ###
项目:BookCloud    作者:livro-aberto    | 项目源码 | 文件源码
def upgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    op.create_table('user_subscription',
    sa.Column('user_id', sa.Integer(), nullable=True),
    sa.Column('named_tag', sa.Integer(), nullable=True),
    sa.ForeignKeyConstraint(['named_tag'], ['named_tag.id'], ),
    sa.ForeignKeyConstraint(['user_id'], ['user.id'], )
    )
    # ### end Alembic commands ###
项目:BookCloud    作者:livro-aberto    | 项目源码 | 文件源码
def downgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    op.add_column('user_tag', sa.Column('id', mysql.INTEGER(display_width=11), nullable=False))
    op.add_column('likes', sa.Column('id', mysql.INTEGER(display_width=11), nullable=False))
    op.add_column('custom_tag', sa.Column('id', mysql.INTEGER(display_width=11), nullable=False))
    # ### end Alembic commands ###
项目:BookCloud    作者:livro-aberto    | 项目源码 | 文件源码
def upgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    op.create_table('user_read_thread',
    sa.Column('user_id', sa.Integer(), nullable=True),
    sa.Column('thread_id', sa.Integer(), nullable=True),
    sa.ForeignKeyConstraint(['thread_id'], ['thread.id'], ),
    sa.ForeignKeyConstraint(['user_id'], ['user.id'], )
    )
    # ### end Alembic commands ###
项目:gloss    作者:openhealthcare    | 项目源码 | 文件源码
def upgrade():
    ### commands auto generated by Alembic - please adjust! ###
    op.add_column('subscription', sa.Column('end_point', sa.String(length=250), nullable=True))
    ### end Alembic commands ###
项目:gloss    作者:openhealthcare    | 项目源码 | 文件源码
def upgrade():
    ### commands auto generated by Alembic - please adjust! ###
    op.add_column('result', sa.Column('profile_description', sa.String(length=250), nullable=True))
    ### end Alembic commands ###
项目:gloss    作者:openhealthcare    | 项目源码 | 文件源码
def upgrade():
    op.drop_table('inpatientlocation')
    op.drop_table('inpatientepisode')

    op.create_table('inpatientadmission',
    sa.Column('id', sa.Integer(), nullable=False),
    sa.Column('updated', sa.DateTime(), nullable=True),
    sa.Column('created', sa.DateTime(), nullable=True),
    sa.Column('datetime_of_admission', sa.DateTime(), nullable=False),
    sa.Column('datetime_of_discharge', sa.DateTime(), nullable=True),
    sa.Column('visit_number', sa.String(length=250), nullable=False),
    sa.Column('admission_diagnosis', sa.String(length=250), nullable=True),
    sa.Column('gloss_reference_id', sa.Integer(), nullable=True),
    sa.ForeignKeyConstraint(['gloss_reference_id'], ['glossolaliareference.id'], ),
    sa.PrimaryKeyConstraint('id')
    )

    op.create_table('inpatientlocation',
    sa.Column('id', sa.Integer(), nullable=False),
    sa.Column('updated', sa.DateTime(), nullable=True),
    sa.Column('created', sa.DateTime(), nullable=True),
    sa.Column('inpatient_admission_id', sa.Integer(), nullable=True),
    sa.Column('datetime_of_transfer', sa.DateTime(), nullable=True),
    sa.Column('ward_code', sa.String(length=250), nullable=True),
    sa.Column('room_code', sa.String(length=250), nullable=True),
    sa.Column('bed_code', sa.String(length=250), nullable=True),
    sa.ForeignKeyConstraint(['inpatient_admission_id'], ['inpatientadmission.id'], ),
    sa.PrimaryKeyConstraint('id')
    )
    ### end Alembic commands ###