Python sqlalchemy.Column() Examples

The following are code examples for showing how to use sqlalchemy.Column(). They are extracted from open source Python projects. You can vote up the examples you like or vote down the exmaples you don't like. You can also save this page to your account.

Example 1
Project: eventor   Author: Acrisel   File: dbschema.py    (license) View Source Project 7 votes vote down vote up
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 
Example 2
Project: eventor   Author: Acrisel   File: dbschema.py    (license) View Source Project 7 votes vote down vote up
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 
Example 3
Project: podigger   Author: perna   File: 012722a93d11_.py    (license) View Source Project 7 votes vote down vote up
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 ### 
Example 4
Project: zipline-chinese   Author: zhanghan1990   File: asset_db_schema.py    (Apache License 2.0) View Source Project 6 votes vote down vote up
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),
    ) 
Example 5
Project: zipline-chinese   Author: zhanghan1990   File: asset_db_schema.py    (Apache License 2.0) View Source Project 6 votes vote down vote up
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'),
        ),
    ) 
Example 6
Project: Flask_Blog   Author: sugarguo   File: descriptor_props.py    (GNU General Public License v3.0) View Source Project 6 votes vote down vote up
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 
Example 7
Project: FRG-Crowdsourcing   Author: 97amarnathk   File: 4ad4fddc76f8_add_privacy_mode_to_user.py    (GNU Affero General Public License v3.0) View Source Project 6 votes vote down vote up
def upgrade():
    op.add_column('user', sa.Column('privacy_mode', sa.Boolean, default=True))
    query = 'UPDATE "user" SET privacy_mode=true;'
    op.execute(query) 
Example 8
Project: FRG-Crowdsourcing   Author: 97amarnathk   File: d1add5e3e65e_projects_stats.py    (GNU Affero General Public License v3.0) View Source Project 6 votes vote down vote up
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)
    ) 
Example 9
Project: FRG-Crowdsourcing   Author: 97amarnathk   File: 0a6628a97161_add_published_to_blogpost.py    (GNU Affero General Public License v3.0) View Source Project 6 votes vote down vote up
def upgrade():
    op.add_column('blogpost', sa.Column('published', sa.Boolean, default=False))
    op.add_column('blogpost', sa.Column('updated', sa.Text,
                                       default=make_timestamp))
    sql = 'update blogpost set published=true'
    op.execute(sql) 
Example 10
Project: cyborg   Author: openstack   File: f50980397351_initial_migration.py    (Apache License 2.0) View Source Project 6 votes vote down vote up
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'
    ) 
Example 11
Project: tuning-box   Author: openstack   File: a86472389a70_remove_hierarchy_for_level_values.py    (Apache License 2.0) View Source Project 6 votes vote down vote up
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']
        ) 
Example 12
Project: bit   Author: codesmart-co   File: 4ad33f99723a_.py    (license) View Source Project 6 votes vote down vote up
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 ### 
Example 13
Project: sqlalchemy_bulk_lazy_loader   Author: operator   File: sqlalchemy_bulk_lazy_loader.py    (license) View Source Project 6 votes vote down vote up
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 
Example 14
Project: sqlalchemy-media   Author: pylover   File: test_delete_orphan.py    (license) View Source Project 6 votes vote down vote up
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)) 
Example 15
Project: sqlalchemy-media   Author: pylover   File: test_delete_orphan.py    (license) View Source Project 6 votes vote down vote up
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)) 
Example 16
Project: sqlalchemy-media   Author: pylover   File: test_delete_orphan.py    (license) View Source Project 6 votes vote down vote up
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)) 
Example 17
Project: sqlalchemy-media   Author: pylover   File: test_decorator.py    (license) View Source Project 6 votes vote down vote up
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() 
Example 18
Project: sqlalchemy-media   Author: pylover   File: test_file.py    (license) View Source Project 6 votes vote down vote up
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!............')) 
Example 19
Project: sqlalchemy-media   Author: pylover   File: test_file.py    (license) View Source Project 6 votes vote down vote up
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) 
Example 20
Project: sqlalchemy-media   Author: pylover   File: test_file.py    (license) View Source Project 6 votes vote down vote up
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() 
Example 21
Project: sqlalchemy-media   Author: pylover   File: test_file.py    (license) View Source Project 6 votes vote down vote up
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)) 
Example 22
Project: sqlalchemy-media   Author: pylover   File: test_file.py    (license) View Source Project 6 votes vote down vote up
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')) 
Example 23
Project: sqlalchemy-media   Author: pylover   File: test_image.py    (license) View Source Project 6 votes vote down vote up
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))) 
Example 24
Project: sqlalchemy-media   Author: pylover   File: test_image.py    (license) View Source Project 6 votes vote down vote up
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') 
Example 25
Project: anormbookmarker   Author: jakeogh   File: TagClassConstructor.py    (license) View Source Project 6 votes vote down vote up
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) 
Example 26
Project: eventor   Author: Acrisel   File: dbschema.py    (license) View Source Project 6 votes vote down vote up
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 
Example 27
Project: Leics   Author: LeicsFrameWork   File: 948333640f64_.py    (license) View Source Project 6 votes vote down vote up
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 ### 
Example 28
Project: QXSConsolas   Author: qxsch   File: descriptor_props.py    (license) View Source Project 6 votes vote down vote up
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 
Example 29
Project: podigger   Author: perna   File: 5c5dc0258b2f_.py    (license) View Source Project 6 votes vote down vote up
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 ### 
Example 30
Project: podigger   Author: perna   File: 34d97cbc759e_.py    (license) View Source Project 6 votes vote down vote up
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 ### 
Example 31
Project: fuel-nailgun-extension-iac   Author: openstack   File: e3b840e64e53_init.py    (Apache License 2.0) View Source Project 5 votes vote down vote up
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')) 
Example 32
Project: fuel-nailgun-extension-iac   Author: openstack   File: adb78f70605d_manage_fuel_node_flag.py    (Apache License 2.0) View Source Project 5 votes vote down vote up
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)
    ) 
Example 33
Project: fuel-nailgun-extension-iac   Author: openstack   File: fc4f164a7b6c_extended_whitelist_with_task_name.py    (Apache License 2.0) View Source Project 5 votes vote down vote up
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)
    ) 
Example 34
Project: fuel-nailgun-extension-iac   Author: openstack   File: 8736ad38ca31_add_whitelist_table.py    (Apache License 2.0) View Source Project 5 votes vote down vote up
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)
    ) 
Example 35
Project: zipline-chinese   Author: zhanghan1990   File: asset_db_schema.py    (Apache License 2.0) View Source Project 5 votes vote down vote up
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),
    ) 
Example 36
Project: zipline-chinese   Author: zhanghan1990   File: asset_db_schema.py    (Apache License 2.0) View Source Project 5 votes vote down vote up
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),
    ) 
Example 37
Project: zipline-chinese   Author: zhanghan1990   File: asset_db_schema.py    (Apache License 2.0) View Source Project 5 votes vote down vote up
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),
    ) 
Example 38
Project: zlktqa   Author: NunchakusHuang   File: 665b177a72a0_.py    (license) View Source Project 5 votes vote down vote up
def upgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    op.add_column('answers', sa.Column('create_time', sa.DateTime(), nullable=True))
    # ### end Alembic commands ### 
Example 39
Project: zlktqa   Author: NunchakusHuang   File: a524f97f269b_.py    (license) View Source Project 5 votes vote down vote up
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 ### 
Example 40
Project: zlktqa   Author: NunchakusHuang   File: 1a1e0c395ff3_.py    (license) View Source Project 5 votes vote down vote up
def upgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    op.add_column('questions', sa.Column('create_time', sa.DateTime(), nullable=True))
    # ### end Alembic commands ### 
Example 41
Project: tasker   Author: DominikPott   File: model.py    (license) View Source Project 5 votes vote down vote up
def task_association_id(cls):
        return Column(Integer, ForeignKey('task_association.id')) 
Example 42
Project: Flask_Blog   Author: sugarguo   File: descriptor_props.py    (GNU General Public License v3.0) View Source Project 5 votes vote down vote up
def columns(self):
        return [a for a in self.attrs if isinstance(a, schema.Column)] 
Example 43
Project: Flask_Blog   Author: sugarguo   File: __init__.py    (GNU General Public License v3.0) View Source Project 5 votes vote down vote up
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 
Example 44
Project: Flask_Blog   Author: sugarguo   File: __init__.py    (GNU General Public License v3.0) View Source Project 5 votes vote down vote up
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 
Example 45
Project: BookCloud   Author: livro-aberto   File: 50e6c12a9a06_add_file_regexp_to_named_tags.py    (GNU General Public License v3.0) View Source Project 5 votes vote down vote up
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 ### 
Example 46
Project: BookCloud   Author: livro-aberto   File: 280d0531befe_create_user_subscription_to_thread_tags.py    (GNU General Public License v3.0) View Source Project 5 votes vote down vote up
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 ### 
Example 47
Project: BookCloud   Author: livro-aberto   File: 9b31d50ade9f_catching_up_after_reorg.py    (GNU General Public License v3.0) View Source Project 5 votes vote down vote up
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 ### 
Example 48
Project: BookCloud   Author: livro-aberto   File: d838fb3c676d_add_user_thread_relation_to_store_read.py    (GNU General Public License v3.0) View Source Project 5 votes vote down vote up
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 ### 
Example 49
Project: gloss   Author: openhealthcare   File: a7d445896d4a_.py    (license) View Source Project 5 votes vote down vote up
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 ### 
Example 50
Project: gloss   Author: openhealthcare   File: 12ba67d8411a_.py    (license) View Source Project 5 votes vote down vote up
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 ###