Esempio n. 1
0
class ObjectVersion(db.Model, Timestamp):
    """Model for storing versions of objects.

    A bucket stores one or more objects identified by a key. Each object is
    versioned where each version is represented by an ``ObjectVersion``.

    An object version can either be 1) a *normal version* which is linked to
    a file instance, or 2) a *delete marker*, which is *not* linked to a file
    instance.

    An normal object version is linked to a physical file on disk via a file
    instance. This allows for multiple object versions to point to the same
    file on disk, to optimize storage efficiency (e.g. useful for snapshotting
    an entire bucket without duplicating the files).

    A delete marker object version represents that the object at hand was
    deleted.

    The latest version of an object is marked using the ``is_head`` property.
    If the latest object version is a delete marker the object will not be
    shown in the bucket.
    """

    __tablename__ = 'files_object'

    bucket_id = db.Column(
        UUIDType,
        db.ForeignKey(Bucket.id, ondelete='RESTRICT'),
        default=uuid.uuid4,
        primary_key=True,
    )
    """Bucket identifier."""

    key = db.Column(
        db.Text().with_variant(mysql.VARCHAR(255), 'mysql'),
        primary_key=True,
    )
    """Key identifying the object."""

    version_id = db.Column(
        UUIDType,
        primary_key=True,
        default=uuid.uuid4,
    )
    """Identifier for the specific version of an object."""

    file_id = db.Column(UUIDType,
                        db.ForeignKey(FileInstance.id, ondelete='RESTRICT'),
                        nullable=True)
    """File instance for this object version.

    A null value in this column defines that the object has been deleted.
    """

    _mimetype = db.Column(
        db.String(255),
        index=True,
        nullable=True,
    )
    """MIME type of the object."""

    is_head = db.Column(db.Boolean(name='is_head'),
                        nullable=False,
                        default=True)
    """Defines if object is the latest version."""

    # Relationships definitions
    bucket = db.relationship(Bucket, backref='objects')
    """Relationship to buckets."""

    file = db.relationship(FileInstance, backref='objects')
    """Relationship to file instance."""
    @validates('key')
    def validate_key(self, key, key_):
        """Validate key."""
        return validate_key(key_)

    def __repr__(self):
        """Return representation of location."""
        return '{0}:{2}:{1}'.format(self.bucket_id, self.key, self.version_id)

    @hybrid_property
    def mimetype(self):
        """Get MIME type of object."""
        if self._mimetype:
            m = self._mimetype
        elif self.key:
            m = mimetypes.guess_type(self.key)[0]
        return m or 'application/octet-stream'

    @mimetype.setter
    def mimetype(self, value):
        """Setter for MIME type."""
        self._mimetype = value

    @property
    def basename(self):
        """Return filename of the object."""
        return basename(self.key)

    @property
    def deleted(self):
        """Determine if object version is a delete marker."""
        return self.file_id is None

    @ensure_no_file()
    @update_bucket_size
    def set_contents(self,
                     stream,
                     chunk_size=None,
                     size=None,
                     size_limit=None,
                     progress_callback=None):
        """Save contents of stream to file instance.

        If a file instance has already been set, this methods raises an
        ``FileInstanceAlreadySetError`` exception.

        :param stream: File-like stream.
        :param size: Size of stream if known.
        :param chunk_size: Desired chunk size to read stream in. It is up to
            the storage interface if it respects this value.
        """
        if size_limit is None:
            size_limit = self.bucket.size_limit

        self.file = FileInstance.create()
        self.file.set_contents(
            stream,
            size_limit=size_limit,
            size=size,
            chunk_size=chunk_size,
            progress_callback=progress_callback,
            default_location=self.bucket.location.uri,
            default_storage_class=self.bucket.default_storage_class,
        )

        return self

    @ensure_no_file()
    @update_bucket_size
    def set_location(self, uri, size, checksum, storage_class=None):
        """Set only URI location of for object.

        Useful to link files on externally controlled storage. If a file
        instance has already been set, this methods raises an
        ``FileInstanceAlreadySetError`` exception.

        :param uri: Full URI to object (which can be interpreted by the storage
            interface).
        :param size: Size of file.
        :param checksum: Checksum of file.
        :param storage_class: Storage class where file is stored ()
        """
        self.file = FileInstance()
        self.file.set_uri(uri, size, checksum, storage_class=storage_class)
        db.session.add(self.file)
        return self

    @ensure_no_file()
    @update_bucket_size
    def set_file(self, fileinstance):
        """Set a file instance."""
        self.file = fileinstance
        return self

    def send_file(self, restricted=True, trusted=False, **kwargs):
        """Wrap around FileInstance's send file."""
        return self.file.send_file(self.basename,
                                   restricted=restricted,
                                   mimetype=self.mimetype,
                                   trusted=trusted,
                                   **kwargs)

    @ensure_is_previous_version()
    def restore(self):
        """Restore this object version to become the latest version.

        Raises an exception if the object is the latest version.
        """
        # Note, copy calls create which will fail if bucket is locked.
        return self.copy()

    @ensure_not_deleted(
        msg=[ObjectVersionError('Cannot copy a delete marker.')])
    def copy(self, bucket=None, key=None):
        """Copy an object version to a given bucket + object key.

        The copy operation is handled completely at the metadata level. The
        actual data on disk is not copied. Instead, the two object versions
        will point to the same physical file (via the same FileInstance).

        .. warning::

           If the destination object exists, it will be replaced by  the new
           object version which will become the latest version.

        :param bucket: The bucket (instance or id) to copy the object to.
            Default: current bucket.
        :param key: Key name of destination object.
            Default: current object key.
        :returns: The copied object version.
        """
        return ObjectVersion.create(
            self.bucket if bucket is None else as_bucket(bucket),
            key or self.key,
            _file_id=self.file_id)

    @ensure_unlocked(getter=lambda o: not o.bucket.locked)
    def remove(self):
        """Permanently remove a specific object version from the database.

        .. warning::

           This by-passes the normal versioning and should only be used when
           you want to permanently delete a specific object version. Otherwise
           use :py:data:`ObjectVersion.delete()`.

           Note the method does not remove the associated file instance which
           must be garbage collected.

        :returns: ``self``.
        """
        with db.session.begin_nested():
            if self.file_id:
                self.bucket.size -= self.file.size
            self.query.filter_by(
                bucket_id=self.bucket_id,
                key=self.key,
                version_id=self.version_id,
            ).delete()

        return self

    @classmethod
    def create(cls,
               bucket,
               key,
               _file_id=None,
               stream=None,
               mimetype=None,
               version_id=None,
               **kwargs):
        """Create a new object in a bucket.

        The created object is by default created as a delete marker. You must
        use ``set_contents()`` or ``set_location()`` in order to change this.

        :param bucket: The bucket (instance or id) to create the object in.
        :param key: Key of object.
        :param _file_id: For internal use.
        :param stream: File-like stream object. Used to set content of object
            immediately after being created.
        :param mimetype: MIME type of the file object if it is known.
        :param kwargs: Keyword arguments passed to ``Object.set_contents()``.
        """
        bucket = as_bucket(bucket)

        if bucket.locked:
            raise BucketLockedError()

        with db.session.begin_nested():
            latest_obj = cls.query.filter(cls.bucket == bucket, cls.key == key,
                                          cls.is_head.is_(True)).one_or_none()
            if latest_obj is not None:
                latest_obj.is_head = False
                db.session.add(latest_obj)

            # By default objects are created in a deleted state (i.e.
            # file_id is null).
            obj = cls(
                bucket=bucket,
                key=key,
                version_id=version_id or uuid.uuid4(),
                is_head=True,
                mimetype=mimetype,
            )
            if _file_id:
                file_ = _file_id if isinstance(_file_id, FileInstance) else \
                    FileInstance.get(_file_id)
                obj.set_file(file_)
            db.session.add(obj)
        if stream:
            obj.set_contents(stream, **kwargs)
        return obj

    @classmethod
    def get(cls, bucket, key, version_id=None):
        """Fetch a specific object.

        By default the latest object version is returned, if
        ``version_id`` is not set.

        :param bucket: The bucket (instance or id) to get the object from.
        :param key: Key of object.
        :param version_id: Specific version of an object.
        """
        filters = [
            cls.bucket_id == as_bucket_id(bucket),
            cls.key == key,
        ]

        if version_id:
            filters.append(cls.version_id == version_id)
        else:
            filters.append(cls.is_head.is_(True))
            filters.append(cls.file_id.isnot(None))

        return cls.query.filter(*filters).one_or_none()

    @classmethod
    def get_versions(cls, bucket, key):
        """Fetch all versions of a specific object.

        :param bucket: The bucket (instance or id) to get the object from.
        :param key: Key of object.
        """
        filters = [
            cls.bucket_id == as_bucket_id(bucket),
            cls.key == key,
        ]

        return cls.query.filter(*filters).order_by(cls.key, cls.created.desc())

    @classmethod
    def delete(cls, bucket, key):
        """Delete an object.

        Technically works by creating a new version which works as a delete
        marker.

        :param bucket: The bucket (instance or id) to delete the object from.
        :param key: Key of object.
        :param version_id: Specific version to delete.
        :returns: Created delete marker object if key exists else ``None``.
        """
        bucket_id = as_bucket_id(bucket)

        obj = cls.get(bucket_id, key)
        if obj:
            return cls.create(as_bucket(bucket), key)
        return None

    @classmethod
    def get_by_bucket(cls, bucket, versions=False):
        """Return query that fetches all the objects in a bucket."""
        bucket_id = bucket.id if isinstance(bucket, Bucket) else bucket

        filters = [
            cls.bucket_id == bucket_id,
        ]

        if not versions:
            filters.append(cls.file_id.isnot(None))
            filters.append(cls.is_head.is_(True))

        return cls.query.filter(*filters).order_by(cls.key, cls.created.desc())

    @classmethod
    def relink_all(cls, old_file, new_file):
        """Relink all object versions (for a given file) to a new file.

        .. warning::

           Use this method with great care.
        """
        assert old_file.checksum == new_file.checksum
        assert old_file.id
        assert new_file.id

        with db.session.begin_nested():
            ObjectVersion.query.filter_by(file_id=str(old_file.id)).update(
                {ObjectVersion.file_id: str(new_file.id)})
def downgrade():
    ### commands auto generated by Alembic - please adjust! ###
    op.drop_column('volunteer_info', 'emergency_response_officer')
    op.drop_constraint('users_ibfk_2', 'users', type_='foreignkey')
    op.drop_constraint('users_ibfk_3', 'users', type_='foreignkey')
    op.create_index('ix_users_password_hash',
                    'users', ['password_hash'],
                    unique=False)
    op.drop_column('users', 'volunteer_id')
    op.drop_column('users', 'contestant_id')
    op.drop_column('users', 'activate')
    op.add_column(
        'tournament_state',
        sa.Column('raffle_config', mysql.VARCHAR(length=2048), nullable=False))
    op.add_column(
        'tournament_state',
        sa.Column('tournament_config',
                  mysql.VARCHAR(length=2048),
                  nullable=False))
    op.drop_column('tournament_state', 'website_accessible_to_teamcaptains')
    op.drop_column('tournament_state', 'system_configured')
    op.drop_column('tournament_state', 'registration_period_started')
    op.drop_column('tournament_state', 'registration_open')
    op.drop_column('tournament_state', 'raffle_system_configured')
    op.drop_column('tournament_state', 'organizer_account_set')
    op.drop_column('teams', 'amount_paid')
    op.add_column(
        'status_info',
        sa.Column('paid',
                  mysql.TINYINT(display_width=1),
                  autoincrement=False,
                  nullable=False))
    op.create_index('ix_status_info_paid',
                    'status_info', ['paid'],
                    unique=False)
    op.drop_column('status_info', 'received_starting_number')
    op.drop_column('status_info', 'feedback_about_information')
    op.add_column(
        'merchandise_info',
        sa.Column('product_id',
                  mysql.INTEGER(display_width=11),
                  autoincrement=False,
                  nullable=False))
    op.add_column(
        'merchandise_info',
        sa.Column('quantity',
                  mysql.INTEGER(display_width=11),
                  autoincrement=False,
                  nullable=False))
    op.drop_index(op.f('ix_merchandise_info_t_shirt_paid'),
                  table_name='merchandise_info')
    op.drop_index(op.f('ix_merchandise_info_mug_paid'),
                  table_name='merchandise_info')
    op.drop_index(op.f('ix_merchandise_info_merchandise_received'),
                  table_name='merchandise_info')
    op.drop_index(op.f('ix_merchandise_info_bag_paid'),
                  table_name='merchandise_info')
    op.drop_column('merchandise_info', 't_shirt_paid')
    op.drop_column('merchandise_info', 't_shirt')
    op.drop_column('merchandise_info', 'mug_paid')
    op.drop_column('merchandise_info', 'mug')
    op.drop_column('merchandise_info', 'merchandise_received')
    op.drop_column('merchandise_info', 'bag_paid')
    op.drop_column('merchandise_info', 'bag')
    op.add_column(
        'additional_info',
        sa.Column('t_shirt', mysql.VARCHAR(length=128), nullable=False))
    op.create_table('team_finances',
                    sa.Column('team_id',
                              mysql.INTEGER(display_width=11),
                              autoincrement=False,
                              nullable=False),
                    sa.Column('paid',
                              mysql.INTEGER(display_width=11),
                              autoincrement=False,
                              nullable=False),
                    sa.ForeignKeyConstraint(['team_id'], ['teams.team_id'],
                                            name='team_finances_ibfk_1'),
                    sa.PrimaryKeyConstraint('team_id'),
                    mysql_default_charset='utf8',
                    mysql_engine='InnoDB')
    op.create_table('merchandise',
                    sa.Column('merchandise_id',
                              mysql.INTEGER(display_width=11),
                              nullable=False),
                    sa.Column('product_name',
                              mysql.VARCHAR(length=128),
                              nullable=False),
                    sa.Column('product_description',
                              mysql.VARCHAR(length=256),
                              nullable=False),
                    sa.Column('price',
                              mysql.INTEGER(display_width=11),
                              autoincrement=False,
                              nullable=False),
                    sa.PrimaryKeyConstraint('merchandise_id'),
                    mysql_default_charset='utf8',
                    mysql_engine='InnoDB')
    op.drop_index(op.f('ix_payment_info_partial_refund'),
                  table_name='payment_info')
    op.drop_index(op.f('ix_payment_info_full_refund'),
                  table_name='payment_info')
    op.drop_index(op.f('ix_payment_info_entry_paid'),
                  table_name='payment_info')
    op.drop_table('payment_info')
    op.drop_table('system_configuration')
    op.drop_table('super_volunteer')
    op.drop_table('raffle_configuration')
    op.drop_table('not_selected_contestant')
    op.drop_table('attended_previous_tournament_contestant')
    # ### end Alembic commands ###
    op.alter_column('contestant_info',
                    'student',
                    existing_type=sa.String(length=128),
                    type_=sa.Boolean)
Esempio n. 3
0
def downgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    op.add_column(
        'user',
        sa.Column('passwword', mysql.VARCHAR(length=100), nullable=False))
    op.drop_column('user', 'password')
Esempio n. 4
0
def downgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    op.alter_column('post',
                    'author_id',
                    existing_type=mysql.VARCHAR(length=100),
                    nullable=False)
Esempio n. 5
0
def downgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    op.add_column('evaluations',
                  sa.Column('month', mysql.VARCHAR(length=16), nullable=False))
    op.drop_column('evaluations', 'date')
Esempio n. 6
0
def downgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    op.alter_column('user',
                    'active',
                    existing_type=sa.Boolean(),
                    type_=mysql.TINYINT(display_width=1),
                    existing_nullable=True)
    op.alter_column('trouble_shooting_version',
                    'shootingFileUrl',
                    existing_type=sa.String(length=1000),
                    type_=mysql.VARCHAR(length=500),
                    existing_nullable=True,
                    autoincrement=False)
    op.alter_column('trouble_shooting',
                    'shootingFileUrl',
                    existing_type=sa.String(length=1000),
                    type_=mysql.VARCHAR(length=500),
                    existing_nullable=True)
    op.alter_column('train_plan_version',
                    'trainPlanFileUrl',
                    existing_type=sa.String(length=1000),
                    type_=mysql.VARCHAR(length=500),
                    existing_nullable=True,
                    autoincrement=False)
    op.alter_column('train_plan',
                    'trainPlanFileUrl',
                    existing_type=sa.String(length=1000),
                    type_=mysql.VARCHAR(length=500),
                    existing_nullable=True)
    op.alter_column('train_file_resource_version',
                    'trainFileResourceUrl',
                    existing_type=sa.String(length=1000),
                    type_=mysql.VARCHAR(length=500),
                    existing_nullable=True,
                    autoincrement=False)
    op.alter_column('train_file_resource',
                    'trainFileResourceUrl',
                    existing_type=sa.String(length=1000),
                    type_=mysql.VARCHAR(length=500),
                    existing_nullable=True)
    op.alter_column('supplier_version',
                    'fileResourceUrl',
                    existing_type=sa.String(length=1000),
                    type_=mysql.VARCHAR(length=500),
                    existing_nullable=True,
                    autoincrement=False)
    op.alter_column('supplier',
                    'fileResourceUrl',
                    existing_type=sa.String(length=1000),
                    type_=mysql.VARCHAR(length=500),
                    existing_nullable=True)
    op.drop_column('scrap_material', 'nextCheckDate')
    op.drop_column('scrap_material', 'lastCheckDate')
    op.drop_column('scrap_material', 'effectiveDate')
    op.alter_column('repair_supplier_version',
                    'fileResourceUrl',
                    existing_type=sa.String(length=1000),
                    type_=mysql.VARCHAR(length=500),
                    existing_nullable=True,
                    autoincrement=False)
    op.alter_column('repair_supplier',
                    'fileResourceUrl',
                    existing_type=sa.String(length=1000),
                    type_=mysql.VARCHAR(length=500),
                    existing_nullable=True)
    op.drop_column('repair_material', 'nextCheckDate')
    op.drop_column('repair_material', 'lastCheckDate')
    op.drop_column('repair_material', 'effectiveDate')
    op.drop_column('put_out_store_material', 'effectiveDate')
    op.alter_column('manufacturer_version',
                    'fileResourceUrl',
                    existing_type=sa.String(length=1000),
                    type_=mysql.VARCHAR(length=500),
                    existing_nullable=True,
                    autoincrement=False)
    op.alter_column('manufacturer',
                    'fileResourceUrl',
                    existing_type=sa.String(length=1000),
                    type_=mysql.VARCHAR(length=500),
                    existing_nullable=True)
    op.alter_column('loan_return_order_version',
                    'loanCategory',
                    existing_type=sa.Enum("一般".encode("utf-8"),
                                          "重要".encode("utf-8")),
                    type_=mysql.VARCHAR(length=255),
                    existing_nullable=True,
                    autoincrement=False)
    op.alter_column('loan_return_order',
                    'loanCategory',
                    existing_type=sa.Enum("一般".encode("utf-8"),
                                          "重要".encode("utf-8")),
                    type_=mysql.VARCHAR(length=255),
                    existing_nullable=False)
    op.drop_column('loan_material', 'effectiveDate')
    op.alter_column('instruction_version',
                    'relateFileUrl',
                    existing_type=sa.String(length=1000),
                    type_=mysql.VARCHAR(length=500),
                    existing_nullable=True,
                    autoincrement=False)
    op.alter_column('instruction',
                    'relateFileUrl',
                    existing_type=sa.String(length=1000),
                    type_=mysql.VARCHAR(length=500),
                    existing_nullable=True)
    op.alter_column('file_resource_version',
                    'fileResourceUrl',
                    existing_type=sa.String(length=1000),
                    type_=mysql.VARCHAR(length=500),
                    existing_nullable=True,
                    autoincrement=False)
    op.alter_column('file_resource_version',
                    'addTime',
                    existing_type=sa.TIMESTAMP(timezone=True),
                    type_=mysql.TIMESTAMP(),
                    existing_nullable=True,
                    autoincrement=False)
    op.alter_column('file_resource',
                    'fileResourceUrl',
                    existing_type=sa.String(length=1000),
                    type_=mysql.VARCHAR(length=500),
                    existing_nullable=True)
    op.alter_column('file_resource',
                    'addTime',
                    existing_type=sa.TIMESTAMP(timezone=True),
                    server_default=sa.text(
                        u'CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP'),
                    type_=mysql.TIMESTAMP(),
                    existing_nullable=False)
    op.alter_column('fault_reports_version',
                    'relateFileUrl',
                    existing_type=sa.String(length=1000),
                    type_=mysql.VARCHAR(length=500),
                    existing_nullable=True,
                    autoincrement=False)
    op.alter_column('fault_reports',
                    'relateFileUrl',
                    existing_type=sa.String(length=1000),
                    type_=mysql.VARCHAR(length=500),
                    existing_nullable=True)
    op.alter_column('examine_repair_record_version',
                    'repairFileUrl',
                    existing_type=sa.String(length=1000),
                    type_=mysql.VARCHAR(length=500),
                    existing_nullable=True,
                    autoincrement=False)
    op.alter_column('examine_repair_record_version',
                    'Soluted',
                    existing_type=sa.Boolean(),
                    type_=mysql.TINYINT(display_width=1),
                    existing_nullable=True,
                    autoincrement=False)
    op.alter_column('examine_repair_record',
                    'repairFileUrl',
                    existing_type=sa.String(length=1000),
                    type_=mysql.VARCHAR(length=500),
                    existing_nullable=True)
    op.alter_column('examine_repair_record',
                    'Soluted',
                    existing_type=sa.Boolean(),
                    type_=mysql.TINYINT(display_width=1),
                    existing_nullable=True)
    op.drop_column('disassemble_material', 'effectiveDate')
    op.alter_column('continues_version',
                    'relateFileUrl',
                    existing_type=sa.String(length=1000),
                    type_=mysql.VARCHAR(length=500),
                    existing_nullable=True,
                    autoincrement=False)
    op.alter_column('continues',
                    'relateFileUrl',
                    existing_type=sa.String(length=1000),
                    type_=mysql.VARCHAR(length=500),
                    existing_nullable=True)
    op.drop_column('borrowing_in_return_material', 'nextCheckDate')
    op.drop_column('borrowing_in_return_material', 'effectiveDate')
    op.alter_column('basic_action',
                    'view',
                    existing_type=sa.Boolean(),
                    type_=mysql.TINYINT(display_width=1),
                    existing_nullable=True)
    op.alter_column('basic_action',
                    'upload_meeting_file',
                    existing_type=sa.Boolean(),
                    type_=mysql.TINYINT(display_width=1),
                    existing_nullable=True)
    op.alter_column('basic_action',
                    'upload_contract_file',
                    existing_type=sa.Boolean(),
                    type_=mysql.TINYINT(display_width=1),
                    existing_nullable=True)
    op.alter_column('basic_action',
                    'submit_review',
                    existing_type=sa.Boolean(),
                    type_=mysql.TINYINT(display_width=1),
                    existing_nullable=True)
    op.alter_column('basic_action',
                    'submit',
                    existing_type=sa.Boolean(),
                    type_=mysql.TINYINT(display_width=1),
                    existing_nullable=True)
    op.alter_column('basic_action',
                    'stored',
                    existing_type=sa.Boolean(),
                    type_=mysql.TINYINT(display_width=1),
                    existing_nullable=True)
    op.alter_column('basic_action',
                    'sent',
                    existing_type=sa.Boolean(),
                    type_=mysql.TINYINT(display_width=1),
                    existing_nullable=True)
    op.alter_column('basic_action',
                    'send',
                    existing_type=sa.Boolean(),
                    type_=mysql.TINYINT(display_width=1),
                    existing_nullable=True)
    op.alter_column('basic_action',
                    'second_approved',
                    existing_type=sa.Boolean(),
                    type_=mysql.TINYINT(display_width=1),
                    existing_nullable=True)
    op.alter_column('basic_action',
                    'second_approve_refuse',
                    existing_type=sa.Boolean(),
                    type_=mysql.TINYINT(display_width=1),
                    existing_nullable=True)
    op.alter_column('basic_action',
                    'review_refuse',
                    existing_type=sa.Boolean(),
                    type_=mysql.TINYINT(display_width=1),
                    existing_nullable=True)
    op.alter_column('basic_action',
                    'review_approve',
                    existing_type=sa.Boolean(),
                    type_=mysql.TINYINT(display_width=1),
                    existing_nullable=True)
    op.alter_column('basic_action',
                    'review_again',
                    existing_type=sa.Boolean(),
                    type_=mysql.TINYINT(display_width=1),
                    existing_nullable=True)
    op.alter_column('basic_action',
                    'review',
                    existing_type=sa.Boolean(),
                    type_=mysql.TINYINT(display_width=1),
                    existing_nullable=True)
    op.alter_column('basic_action',
                    'reserve_again',
                    existing_type=sa.Boolean(),
                    type_=mysql.TINYINT(display_width=1),
                    existing_nullable=True)
    op.alter_column('basic_action',
                    'receive',
                    existing_type=sa.Boolean(),
                    type_=mysql.TINYINT(display_width=1),
                    existing_nullable=True)
    op.alter_column('basic_action',
                    'put_in_store',
                    existing_type=sa.Boolean(),
                    type_=mysql.TINYINT(display_width=1),
                    existing_nullable=True)
    op.alter_column('basic_action',
                    'purchase_application',
                    existing_type=sa.Boolean(),
                    type_=mysql.TINYINT(display_width=1),
                    existing_nullable=True)
    op.alter_column('basic_action',
                    'out_store_part',
                    existing_type=sa.Boolean(),
                    type_=mysql.TINYINT(display_width=1),
                    existing_nullable=True)
    op.alter_column('basic_action',
                    'out_store_finish',
                    existing_type=sa.Boolean(),
                    type_=mysql.TINYINT(display_width=1),
                    existing_nullable=True)
    op.alter_column('basic_action',
                    'in_store_part',
                    existing_type=sa.Boolean(),
                    type_=mysql.TINYINT(display_width=1),
                    existing_nullable=True)
    op.alter_column('basic_action',
                    'in_store_finish',
                    existing_type=sa.Boolean(),
                    type_=mysql.TINYINT(display_width=1),
                    existing_nullable=True)
    op.alter_column('basic_action',
                    'finish',
                    existing_type=sa.Boolean(),
                    type_=mysql.TINYINT(display_width=1),
                    existing_nullable=True)
    op.alter_column('basic_action',
                    'edit_bound_status',
                    existing_type=sa.Boolean(),
                    type_=mysql.TINYINT(display_width=1),
                    existing_nullable=True)
    op.alter_column('basic_action',
                    'edit',
                    existing_type=sa.Boolean(),
                    type_=mysql.TINYINT(display_width=1),
                    existing_nullable=True)
    op.alter_column('basic_action',
                    'delete',
                    existing_type=sa.Boolean(),
                    type_=mysql.TINYINT(display_width=1),
                    existing_nullable=True)
    op.alter_column('basic_action',
                    'create_st',
                    existing_type=sa.Boolean(),
                    type_=mysql.TINYINT(display_width=1),
                    existing_nullable=True)
    op.alter_column('basic_action',
                    'create_scrap',
                    existing_type=sa.Boolean(),
                    type_=mysql.TINYINT(display_width=1),
                    existing_nullable=True)
    op.alter_column('basic_action',
                    'create_rw',
                    existing_type=sa.Boolean(),
                    type_=mysql.TINYINT(display_width=1),
                    existing_nullable=True)
    op.alter_column('basic_action',
                    'create_rp_rt',
                    existing_type=sa.Boolean(),
                    type_=mysql.TINYINT(display_width=1),
                    existing_nullable=True)
    op.alter_column('basic_action',
                    'create_rf',
                    existing_type=sa.Boolean(),
                    type_=mysql.TINYINT(display_width=1),
                    existing_nullable=True)
    op.alter_column('basic_action',
                    'create_out',
                    existing_type=sa.Boolean(),
                    type_=mysql.TINYINT(display_width=1),
                    existing_nullable=True)
    op.alter_column('basic_action',
                    'create_mr',
                    existing_type=sa.Boolean(),
                    type_=mysql.TINYINT(display_width=1),
                    existing_nullable=True)
    op.alter_column('basic_action',
                    'create_lr',
                    existing_type=sa.Boolean(),
                    type_=mysql.TINYINT(display_width=1),
                    existing_nullable=True)
    op.alter_column('basic_action',
                    'create_in',
                    existing_type=sa.Boolean(),
                    type_=mysql.TINYINT(display_width=1),
                    existing_nullable=True)
    op.alter_column('basic_action',
                    'create_er',
                    existing_type=sa.Boolean(),
                    type_=mysql.TINYINT(display_width=1),
                    existing_nullable=True)
    op.alter_column('basic_action',
                    'create_eo',
                    existing_type=sa.Boolean(),
                    type_=mysql.TINYINT(display_width=1),
                    existing_nullable=True)
    op.alter_column('basic_action',
                    'create_br',
                    existing_type=sa.Boolean(),
                    type_=mysql.TINYINT(display_width=1),
                    existing_nullable=True)
    op.alter_column('basic_action',
                    'create_as',
                    existing_type=sa.Boolean(),
                    type_=mysql.TINYINT(display_width=1),
                    existing_nullable=True)
    op.alter_column('basic_action',
                    'create',
                    existing_type=sa.Boolean(),
                    type_=mysql.TINYINT(display_width=1),
                    existing_nullable=True)
    op.alter_column('basic_action',
                    'check_complete',
                    existing_type=sa.Boolean(),
                    type_=mysql.TINYINT(display_width=1),
                    existing_nullable=True)
    op.alter_column('basic_action',
                    'cancel',
                    existing_type=sa.Boolean(),
                    type_=mysql.TINYINT(display_width=1),
                    existing_nullable=True)
    op.alter_column('basic_action',
                    'borrowing_in_return',
                    existing_type=sa.Boolean(),
                    type_=mysql.TINYINT(display_width=1),
                    existing_nullable=True)
    op.alter_column('basic_action',
                    'borrow_application',
                    existing_type=sa.Boolean(),
                    type_=mysql.TINYINT(display_width=1),
                    existing_nullable=True)
    op.alter_column('basic_action',
                    'approved',
                    existing_type=sa.Boolean(),
                    type_=mysql.TINYINT(display_width=1),
                    existing_nullable=True)
    op.alter_column('basic_action',
                    'approve_refuse',
                    existing_type=sa.Boolean(),
                    type_=mysql.TINYINT(display_width=1),
                    existing_nullable=True)
    op.alter_column('basic_action',
                    'approve',
                    existing_type=sa.Boolean(),
                    type_=mysql.TINYINT(display_width=1),
                    existing_nullable=True)
    op.add_column(
        'assemble_application_list',
        sa.Column('lastCheckTime', mysql.VARCHAR(length=255), nullable=True))
    op.add_column(
        'assemble_application_list',
        sa.Column('nextCheckTime', mysql.VARCHAR(length=255), nullable=True))
    op.drop_column('assemble_application_list', 'nextCheckDate')
    op.drop_column('assemble_application_list', 'lastCheckDate')
    op.drop_column('assemble_application_list', 'effectiveDate')
    op.drop_column('airmaterial_category_version', 'isOrNotHavePeriodCheck')
    op.drop_column('airmaterial_category_version', 'isOrNotHaveEffectiveDate')
    op.drop_column('airmaterial_category', 'isOrNotHavePeriodCheck')
    op.drop_column('airmaterial_category', 'isOrNotHaveEffectiveDate')
    op.alter_column('air_lxgz_version',
                    'fileUrl',
                    existing_type=sa.String(length=1000),
                    type_=mysql.VARCHAR(length=500),
                    existing_nullable=True,
                    autoincrement=False)
    op.alter_column('air_lxgz',
                    'fileUrl',
                    existing_type=sa.String(length=1000),
                    type_=mysql.VARCHAR(length=500),
                    existing_nullable=True)
Esempio n. 7
0
def downgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    op.add_column('post', sa.Column('reason', mysql.VARCHAR(length=256), nullable=True))
def downgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    op.add_column(
        'videoscramble',
        sa.Column('video_path', mysql.VARCHAR(length=200), nullable=True))
    op.drop_column('videoscramble', 'video_filename')
Esempio n. 9
0
def upgrade():
    op.create_table('geolocations',
                    sa.Column('full_address',
                              mysql.VARCHAR(collation='utf8mb4_unicode_ci',
                                            length=191),
                              nullable=False),
                    sa.Column('coordinates_x', mysql.FLOAT(), nullable=True),
                    sa.Column('coordinates_y', mysql.FLOAT(), nullable=True),
                    sa.PrimaryKeyConstraint('full_address'),
                    mysql_collate='utf8mb4_unicode_ci',
                    mysql_default_charset='utf8mb4',
                    mysql_engine='InnoDB')
    op.create_table('etablissements_backoffice',
                    sa.Column('siret',
                              mysql.VARCHAR(collation='utf8mb4_unicode_ci',
                                            length=191),
                              nullable=False),
                    sa.Column('raisonsociale',
                              mysql.VARCHAR(collation='utf8mb4_unicode_ci',
                                            length=191),
                              nullable=True),
                    sa.Column('enseigne',
                              mysql.VARCHAR(collation='utf8mb4_unicode_ci',
                                            length=191),
                              nullable=True),
                    sa.Column('codenaf',
                              mysql.VARCHAR(collation='utf8mb4_unicode_ci',
                                            length=191),
                              nullable=True),
                    sa.Column('trancheeffectif',
                              mysql.VARCHAR(collation='utf8mb4_unicode_ci',
                                            length=191),
                              nullable=True),
                    sa.Column('numerorue',
                              mysql.VARCHAR(collation='utf8mb4_unicode_ci',
                                            length=191),
                              nullable=True),
                    sa.Column('libellerue',
                              mysql.VARCHAR(collation='utf8mb4_unicode_ci',
                                            length=191),
                              nullable=True),
                    sa.Column('codepostal',
                              mysql.VARCHAR(collation='utf8mb4_unicode_ci',
                                            length=11),
                              nullable=True),
                    sa.Column('tel',
                              mysql.VARCHAR(collation='utf8mb4_unicode_ci',
                                            length=191),
                              nullable=True),
                    sa.Column('email',
                              mysql.VARCHAR(collation='utf8mb4_unicode_ci',
                                            length=191),
                              nullable=True),
                    sa.Column('website',
                              mysql.VARCHAR(collation='utf8mb4_unicode_ci',
                                            length=191),
                              nullable=True),
                    sa.Column('flag_alternance',
                              mysql.TINYINT(display_width=1),
                              autoincrement=False,
                              nullable=False),
                    sa.Column('flag_junior',
                              mysql.TINYINT(display_width=1),
                              autoincrement=False,
                              nullable=False),
                    sa.Column('flag_senior',
                              mysql.TINYINT(display_width=1),
                              autoincrement=False,
                              nullable=False),
                    sa.Column('flag_handicap',
                              mysql.TINYINT(display_width=1),
                              autoincrement=False,
                              nullable=False),
                    sa.Column('has_multi_geolocations',
                              mysql.TINYINT(display_width=1),
                              autoincrement=False,
                              nullable=False),
                    sa.Column('codecommune',
                              mysql.VARCHAR(collation='utf8mb4_unicode_ci',
                                            length=191),
                              nullable=True),
                    sa.Column('coordinates_x', mysql.FLOAT(), nullable=True),
                    sa.Column('coordinates_y', mysql.FLOAT(), nullable=True),
                    sa.Column('departement',
                              mysql.VARCHAR(collation='utf8mb4_unicode_ci',
                                            length=11),
                              nullable=True),
                    sa.Column('score',
                              mysql.INTEGER(display_width=11),
                              autoincrement=False,
                              nullable=True),
                    sa.Column('semester-1',
                              mysql.DOUBLE(asdecimal=True),
                              nullable=True),
                    sa.Column('semester-2',
                              mysql.DOUBLE(asdecimal=True),
                              nullable=True),
                    sa.Column('semester-3',
                              mysql.DOUBLE(asdecimal=True),
                              nullable=True),
                    sa.Column('semester-4',
                              mysql.DOUBLE(asdecimal=True),
                              nullable=True),
                    sa.Column('semester-5',
                              mysql.DOUBLE(asdecimal=True),
                              nullable=True),
                    sa.Column('semester-6',
                              mysql.DOUBLE(asdecimal=True),
                              nullable=True),
                    sa.Column('semester-7',
                              mysql.DOUBLE(asdecimal=True),
                              nullable=True),
                    sa.Column('effectif',
                              mysql.DOUBLE(asdecimal=True),
                              nullable=True),
                    sa.Column('score_regr', mysql.FLOAT(), nullable=True),
                    sa.PrimaryKeyConstraint('siret'),
                    mysql_collate='utf8mb4_unicode_ci',
                    mysql_default_charset='utf8mb4',
                    mysql_engine='InnoDB')
Esempio n. 10
0
def downgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    op.alter_column('user_access',
                    'name',
                    existing_type=mysql.VARCHAR(length=50),
                    nullable=False)
Esempio n. 11
0
def downgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    op.create_table('article',
                    sa.Column('id',
                              mysql.INTEGER(display_width=11),
                              autoincrement=True,
                              nullable=False),
                    sa.Column('title',
                              mysql.VARCHAR(length=50),
                              nullable=False),
                    sa.Column('uid',
                              mysql.INTEGER(display_width=11),
                              autoincrement=False,
                              nullable=True),
                    sa.ForeignKeyConstraint(['uid'], ['user.id'],
                                            name='article_ibfk_1'),
                    sa.PrimaryKeyConstraint('id'),
                    mysql_collate='utf8mb4_0900_ai_ci',
                    mysql_default_charset='utf8mb4',
                    mysql_engine='InnoDB')
    op.create_table('myflask',
                    sa.Column('id',
                              mysql.INTEGER(display_width=11),
                              autoincrement=True,
                              nullable=False),
                    sa.Column('name', mysql.VARCHAR(length=50), nullable=True),
                    sa.Column('class_name',
                              mysql.ENUM('python', 'flask', 'django'),
                              nullable=True),
                    sa.Column('create_time', sa.DATE(), nullable=True),
                    sa.PrimaryKeyConstraint('id'),
                    mysql_collate='utf8mb4_0900_ai_ci',
                    mysql_default_charset='utf8mb4',
                    mysql_engine='InnoDB')
    op.create_table('jian',
                    sa.Column('id',
                              mysql.INTEGER(display_width=11),
                              autoincrement=True,
                              nullable=False),
                    sa.Column('name', mysql.VARCHAR(length=50), nullable=True),
                    sa.Column('age',
                              mysql.INTEGER(display_width=11),
                              autoincrement=False,
                              nullable=True),
                    sa.PrimaryKeyConstraint('id'),
                    mysql_collate='utf8mb4_0900_ai_ci',
                    mysql_default_charset='utf8mb4',
                    mysql_engine='InnoDB')
    op.create_table('person',
                    sa.Column('id',
                              mysql.INTEGER(display_width=11),
                              autoincrement=True,
                              nullable=False),
                    sa.Column('name', mysql.VARCHAR(length=50), nullable=True),
                    sa.Column('age',
                              mysql.INTEGER(display_width=11),
                              autoincrement=False,
                              nullable=True),
                    sa.PrimaryKeyConstraint('id'),
                    mysql_collate='utf8mb4_0900_ai_ci',
                    mysql_default_charset='utf8mb4',
                    mysql_engine='InnoDB')
Esempio n. 12
0
def downgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    op.create_table('delivery_order',
    sa.Column('id', mysql.BIGINT(display_width=20), autoincrement=True, nullable=False),
    sa.Column('user_id', mysql.VARCHAR(length=255), nullable=False),
    sa.Column('order_id', mysql.VARCHAR(length=255), nullable=False),
    sa.Column('pickup_address', mysql.VARCHAR(length=255), nullable=False),
    sa.Column('pickup_contact', mysql.VARCHAR(length=255), nullable=False),
    sa.Column('pickup_contact_number', mysql.VARCHAR(length=255), nullable=False),
    sa.Column('dropoff_address', mysql.VARCHAR(length=255), nullable=False),
    sa.Column('dropoff_contact', mysql.VARCHAR(length=255), nullable=False),
    sa.Column('dropoff_contact_number', mysql.VARCHAR(length=255), nullable=False),
    sa.Column('item_value_cost', mysql.BIGINT(display_width=20), autoincrement=False, nullable=False),
    sa.Column('notes', mysql.TEXT(), nullable=False),
    sa.Column('delivery_fee', mysql.DOUBLE(asdecimal=True), nullable=False),
    sa.Column('invoice_id', mysql.VARCHAR(length=255), nullable=False),
    sa.Column('mpesa_payment_id', mysql.VARCHAR(length=255), nullable=True),
    sa.Column('date_created', mysql.BIGINT(display_width=20), autoincrement=False, nullable=False),
    sa.Column('order_status', mysql.VARCHAR(length=255), server_default=sa.text("'New'"), nullable=True),
    sa.Column('rider_id', mysql.VARCHAR(length=255), nullable=True),
    sa.Column('rider_pickup_date', mysql.BIGINT(display_width=20), autoincrement=False, nullable=True),
    sa.Column('rider_delivery_date', mysql.BIGINT(display_width=20), autoincrement=False, nullable=True),
    sa.Column('rider_notes', mysql.TEXT(), nullable=True),
    sa.Column('user_feedback', mysql.TEXT(), nullable=True),
    sa.PrimaryKeyConstraint('id'),
    mysql_default_charset='utf8',
    mysql_engine='InnoDB'
    )
    op.create_table('user',
    sa.Column('id', mysql.BIGINT(display_width=20), autoincrement=True, nullable=False),
    sa.Column('user_id', mysql.VARCHAR(length=255), nullable=False),
    sa.Column('firstname', mysql.VARCHAR(length=255), nullable=False),
    sa.Column('lastname', mysql.VARCHAR(length=255), nullable=False),
    sa.Column('email', mysql.VARCHAR(length=255), nullable=False),
    sa.Column('phone_number', mysql.VARCHAR(length=255), nullable=False),
    sa.Column('push_notificaiton_id', mysql.TEXT(), nullable=True),
    sa.Column('date_created', mysql.VARCHAR(length=255), nullable=False),
    sa.Column('phone_number_verified', mysql.INTEGER(display_width=11), server_default=sa.text('0'), autoincrement=False, nullable=False),
    sa.PrimaryKeyConstraint('id'),
    mysql_default_charset='utf8',
    mysql_engine='InnoDB'
    )
    op.create_table('login',
    sa.Column('id', mysql.BIGINT(display_width=20), autoincrement=True, nullable=False),
    sa.Column('user_id', mysql.VARCHAR(length=255), nullable=False),
    sa.Column('email_address', mysql.VARCHAR(length=255), nullable=False),
    sa.Column('password', mysql.VARCHAR(length=255), nullable=False),
    sa.Column('role', mysql.INTEGER(display_width=11), autoincrement=False, nullable=False),
    sa.Column('status', mysql.INTEGER(display_width=11), autoincrement=False, nullable=False),
    sa.Column('date_created', mysql.BIGINT(display_width=20), autoincrement=False, nullable=False),
    sa.Column('last_login', mysql.BIGINT(display_width=20), autoincrement=False, nullable=True),
    sa.PrimaryKeyConstraint('id'),
    mysql_default_charset='utf8',
    mysql_engine='InnoDB'
    )
    op.drop_table('users')
    op.drop_table('blacklist_tokens')
def downgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    op.alter_column('contestant_model',
                    'phone',
                    existing_type=mysql.VARCHAR(length=16),
                    nullable=False)
Esempio n. 14
0
class Users(base):
    __tablename__ = 'users'
    id = Column('id', mysql.INTEGER, primary_key=True, autoincrement=True)
    username = Column('username', mysql.VARCHAR(12), nullable=False)
    password = Column('password', mysql.VARCHAR(12), nullable=False)
Esempio n. 15
0
def downgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    op.drop_constraint(None, 'lead_requests', type_='foreignkey')
    op.drop_column('lead_requests', 'user_id')
    op.create_table('subscriptions',
                    sa.Column('plan_id',
                              mysql.INTEGER(display_width=11),
                              autoincrement=False,
                              nullable=False),
                    sa.Column('user_id',
                              mysql.INTEGER(display_width=11),
                              autoincrement=False,
                              nullable=False),
                    sa.Column('yearly',
                              mysql.TINYINT(display_width=1),
                              autoincrement=False,
                              nullable=True),
                    sa.Column('subscription_date',
                              mysql.DATETIME(),
                              nullable=True),
                    sa.Column('next_payment', mysql.DATETIME(), nullable=True),
                    sa.ForeignKeyConstraint(['plan_id'], ['plans.id'],
                                            name='subscriptions_ibfk_1'),
                    sa.ForeignKeyConstraint(['user_id'], ['users.id'],
                                            name='subscriptions_ibfk_2'),
                    sa.PrimaryKeyConstraint('plan_id', 'user_id'),
                    mysql_default_charset='utf8',
                    mysql_engine='InnoDB')
    op.create_table('leads',
                    sa.Column('id',
                              mysql.INTEGER(display_width=11),
                              autoincrement=True,
                              nullable=False),
                    sa.Column('creation_date', mysql.DATETIME(),
                              nullable=True),
                    sa.Column('company_name',
                              mysql.VARCHAR(length=120),
                              nullable=True),
                    sa.Column('company_address',
                              mysql.VARCHAR(length=120),
                              nullable=True),
                    sa.Column('company_postal_code',
                              mysql.VARCHAR(length=30),
                              nullable=True),
                    sa.Column('company_city',
                              mysql.VARCHAR(length=60),
                              nullable=True),
                    sa.Column('company_email',
                              mysql.VARCHAR(length=120),
                              nullable=True),
                    sa.Column('company_email_bcc',
                              mysql.VARCHAR(length=120),
                              nullable=True),
                    sa.Column('company_phone',
                              mysql.VARCHAR(length=60),
                              nullable=True),
                    sa.Column('company_activity_field',
                              mysql.VARCHAR(length=60),
                              nullable=False),
                    sa.Column('owner_firstname',
                              mysql.VARCHAR(length=60),
                              nullable=True),
                    sa.Column('owner_lastname',
                              mysql.VARCHAR(length=60),
                              nullable=True),
                    sa.PrimaryKeyConstraint('id'),
                    mysql_default_charset='utf8',
                    mysql_engine='InnoDB')
Esempio n. 16
0
def downgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    op.add_column('classes', sa.Column('course_code', mysql.VARCHAR(length=20), nullable=True))
    op.create_foreign_key('classes_ibfk_3', 'classes', 'course', ['course_code'], ['code'], onupdate='CASCADE')
Esempio n. 17
0
def downgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    op.create_table('service',
                    sa.Column('id',
                              mysql.INTEGER(display_width=11),
                              autoincrement=True,
                              nullable=False),
                    sa.Column('url',
                              mysql.VARCHAR(collation='utf8_unicode_ci',
                                            length=140),
                              nullable=True),
                    sa.PrimaryKeyConstraint('id'),
                    mysql_collate='utf8_unicode_ci',
                    mysql_default_charset='utf8',
                    mysql_engine='InnoDB')
    op.create_table('weather',
                    sa.Column('id',
                              mysql.INTEGER(display_width=11),
                              autoincrement=True,
                              nullable=False),
                    sa.Column('service_id',
                              mysql.INTEGER(display_width=11),
                              autoincrement=False,
                              nullable=True),
                    sa.Column('city_name',
                              mysql.VARCHAR(collation='utf8_unicode_ci',
                                            length=80),
                              nullable=True),
                    sa.Column('country',
                              mysql.VARCHAR(collation='utf8_unicode_ci',
                                            length=5),
                              nullable=True),
                    sa.Column('latitude', mysql.FLOAT(), nullable=True),
                    sa.Column('longitude', mysql.FLOAT(), nullable=True),
                    sa.Column('main',
                              mysql.VARCHAR(collation='utf8_unicode_ci',
                                            length=20),
                              nullable=True),
                    sa.Column('description',
                              mysql.VARCHAR(collation='utf8_unicode_ci',
                                            length=40),
                              nullable=True),
                    sa.Column('clouds', mysql.FLOAT(), nullable=True),
                    sa.Column('temperature', mysql.FLOAT(), nullable=True),
                    sa.Column('temp_min', mysql.FLOAT(), nullable=True),
                    sa.Column('temp_max', mysql.FLOAT(), nullable=True),
                    sa.Column('pressure', mysql.FLOAT(), nullable=True),
                    sa.Column('humidity', mysql.FLOAT(), nullable=True),
                    sa.Column('wind_speed', mysql.FLOAT(), nullable=True),
                    sa.Column('wind_deg', mysql.FLOAT(), nullable=True),
                    sa.Column('time',
                              mysql.VARCHAR(collation='utf8_unicode_ci',
                                            length=30),
                              nullable=True),
                    sa.ForeignKeyConstraint(['service_id'], ['service.id'],
                                            name='weather_ibfk_1',
                                            ondelete='cascade'),
                    sa.PrimaryKeyConstraint('id'),
                    mysql_collate='utf8_unicode_ci',
                    mysql_default_charset='utf8',
                    mysql_engine='InnoDB')
    op.create_index('ix_weather_time', 'weather', ['time'], unique=False)
    op.create_index('ix_weather_temperature',
                    'weather', ['temperature'],
                    unique=False)
    op.create_index('ix_weather_main', 'weather', ['main'], unique=False)
    op.create_index('ix_weather_city_name',
                    'weather', ['city_name'],
                    unique=False)
Esempio n. 18
0
def downgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    op.add_column('books',
                  sa.Column('autor', mysql.VARCHAR(length=32), nullable=True))
    op.drop_column('books', 'author')
    op.drop_table('booksection')
Esempio n. 19
0
def downgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    op.add_column('project', sa.Column('token', mysql.VARCHAR(length=50), nullable=True))
    op.drop_column('project', 'tokens')
Esempio n. 20
0
def downgrade():
    ### commands auto generated by Alembic - please adjust! ###
    with op.batch_alter_table('worker', schema=None) as batch_op:
        batch_op.drop_column('log')

    op.create_table('task',
                    sa.Column('id',
                              mysql.INTEGER(display_width=11),
                              nullable=False),
                    sa.Column('server_id',
                              mysql.INTEGER(display_width=11),
                              autoincrement=False,
                              nullable=False),
                    sa.Column('worker_id',
                              mysql.INTEGER(display_width=11),
                              autoincrement=False,
                              nullable=True),
                    sa.Column('priority',
                              mysql.INTEGER(display_width=11),
                              autoincrement=False,
                              nullable=True),
                    sa.Column('frame_start',
                              mysql.INTEGER(display_width=11),
                              autoincrement=False,
                              nullable=True),
                    sa.Column('frame_end',
                              mysql.INTEGER(display_width=11),
                              autoincrement=False,
                              nullable=True),
                    sa.Column('frame_current',
                              mysql.INTEGER(display_width=11),
                              autoincrement=False,
                              nullable=True),
                    sa.Column('status',
                              mysql.VARCHAR(length=10),
                              nullable=True),
                    sa.Column('format',
                              mysql.VARCHAR(length=10),
                              nullable=True),
                    sa.Column('file_path_linux',
                              mysql.VARCHAR(length=256),
                              nullable=True),
                    sa.Column('file_path_win',
                              mysql.VARCHAR(length=256),
                              nullable=True),
                    sa.Column('file_path_osx',
                              mysql.VARCHAR(length=256),
                              nullable=True),
                    sa.Column('settings',
                              mysql.VARCHAR(length=50),
                              nullable=True),
                    sa.Column('pid',
                              mysql.INTEGER(display_width=11),
                              autoincrement=False,
                              nullable=True),
                    sa.Column('output_path_linux', mysql.TEXT(),
                              nullable=True),
                    sa.Column('output_path_osx', mysql.TEXT(), nullable=True),
                    sa.Column('output_path_win', mysql.TEXT(), nullable=True),
                    sa.PrimaryKeyConstraint('id'),
                    mysql_default_charset=u'latin1',
                    mysql_engine=u'InnoDB')
    op.create_table('task_type',
                    sa.Column('id',
                              mysql.INTEGER(display_width=11),
                              nullable=False),
                    sa.Column('name', mysql.VARCHAR(length=40),
                              nullable=False),
                    sa.Column('url', mysql.VARCHAR(length=128),
                              nullable=False),
                    sa.Column('pre_command',
                              mysql.VARCHAR(length=256),
                              nullable=True),
                    sa.Column('post_command',
                              mysql.VARCHAR(length=256),
                              nullable=True),
                    sa.PrimaryKeyConstraint('id'),
                    mysql_default_charset=u'latin1',
                    mysql_engine=u'InnoDB')
def downgrade():
    ### commands auto generated by Alembic - please adjust! ###
    op.create_table(
        'collection_edit_log',
        sa.Column('id', mysql.INTEGER(display_width=11), nullable=False),
        sa.Column('created_at', mysql.DATETIME(), nullable=True),
        sa.Column('kind',
                  mysql.INTEGER(display_width=11),
                  autoincrement=False,
                  nullable=False),
        sa.Column('before', mysql.VARCHAR(length=200), nullable=True),
        sa.Column('before_id',
                  mysql.INTEGER(display_width=11),
                  autoincrement=False,
                  nullable=True),
        sa.Column('after', mysql.VARCHAR(length=200), nullable=True),
        sa.Column('after_id',
                  mysql.INTEGER(display_width=11),
                  autoincrement=False,
                  nullable=True),
        sa.Column('compare', mysql.VARCHAR(length=500), nullable=True),
        sa.Column('user_id',
                  mysql.INTEGER(display_width=11),
                  autoincrement=False,
                  nullable=True),
        sa.Column('collection_id',
                  mysql.INTEGER(display_width=11),
                  autoincrement=False,
                  nullable=True),
        sa.ForeignKeyConstraint(['collection_id'], [u'collection.id'],
                                name=u'collection_edit_log_ibfk_1'),
        sa.ForeignKeyConstraint(['user_id'], [u'user.id'],
                                name=u'collection_edit_log_ibfk_2'),
        sa.PrimaryKeyConstraint('id'),
        mysql_default_charset=u'utf8',
        mysql_engine=u'InnoDB')
    op.create_table('collection_kind',
                    sa.Column('id',
                              mysql.INTEGER(display_width=11),
                              nullable=False),
                    sa.Column('created_at', mysql.DATETIME(), nullable=True),
                    sa.Column('name', mysql.VARCHAR(length=100),
                              nullable=True),
                    sa.Column('show_order',
                              mysql.INTEGER(display_width=11),
                              autoincrement=False,
                              nullable=True),
                    sa.PrimaryKeyConstraint('id'),
                    mysql_default_charset=u'utf8',
                    mysql_engine=u'InnoDB')
    op.create_table('invitation_code',
                    sa.Column('id',
                              mysql.INTEGER(display_width=11),
                              nullable=False),
                    sa.Column('code', mysql.VARCHAR(length=200),
                              nullable=True),
                    sa.Column('email',
                              mysql.VARCHAR(length=100),
                              nullable=True),
                    sa.Column('used',
                              mysql.TINYINT(display_width=1),
                              autoincrement=False,
                              nullable=True),
                    sa.Column('sended_at', mysql.DATETIME(), nullable=True),
                    sa.Column('created_at', mysql.DATETIME(), nullable=True),
                    sa.Column('user_id',
                              mysql.INTEGER(display_width=11),
                              autoincrement=False,
                              nullable=True),
                    sa.Column('sender_id',
                              mysql.INTEGER(display_width=11),
                              autoincrement=False,
                              nullable=True),
                    sa.ForeignKeyConstraint(['sender_id'], [u'user.id'],
                                            name=u'invitation_code_ibfk_2'),
                    sa.ForeignKeyConstraint(['user_id'], [u'user.id'],
                                            name=u'invitation_code_ibfk_1'),
                    sa.PrimaryKeyConstraint('id'),
                    mysql_default_charset=u'utf8',
                    mysql_engine=u'InnoDB')
    op.create_table('collection_like',
                    sa.Column('id',
                              mysql.INTEGER(display_width=11),
                              nullable=False),
                    sa.Column('created_at', mysql.DATETIME(), nullable=True),
                    sa.Column('user_id',
                              mysql.INTEGER(display_width=11),
                              autoincrement=False,
                              nullable=True),
                    sa.Column('collection_id',
                              mysql.INTEGER(display_width=11),
                              autoincrement=False,
                              nullable=True),
                    sa.ForeignKeyConstraint(['collection_id'],
                                            [u'collection.id'],
                                            name=u'collection_like_ibfk_1'),
                    sa.ForeignKeyConstraint(['user_id'], [u'user.id'],
                                            name=u'collection_like_ibfk_2'),
                    sa.PrimaryKeyConstraint('id'),
                    mysql_default_charset=u'utf8',
                    mysql_engine=u'InnoDB')
    op.create_table('piece_edit_log',
                    sa.Column('id',
                              mysql.INTEGER(display_width=11),
                              nullable=False),
                    sa.Column('created_at', mysql.DATETIME(), nullable=True),
                    sa.Column('user_id',
                              mysql.INTEGER(display_width=11),
                              autoincrement=False,
                              nullable=True),
                    sa.Column('piece_id',
                              mysql.INTEGER(display_width=11),
                              autoincrement=False,
                              nullable=True),
                    sa.Column('kind',
                              mysql.INTEGER(display_width=11),
                              autoincrement=False,
                              nullable=False),
                    sa.Column('after',
                              mysql.VARCHAR(length=200),
                              nullable=True),
                    sa.Column('after_id',
                              mysql.INTEGER(display_width=11),
                              autoincrement=False,
                              nullable=True),
                    sa.Column('before',
                              mysql.VARCHAR(length=200),
                              nullable=True),
                    sa.Column('before_id',
                              mysql.INTEGER(display_width=11),
                              autoincrement=False,
                              nullable=True),
                    sa.Column('compare',
                              mysql.VARCHAR(length=500),
                              nullable=True),
                    sa.ForeignKeyConstraint(['piece_id'], [u'piece.id'],
                                            name=u'piece_edit_log_ibfk_2'),
                    sa.ForeignKeyConstraint(['user_id'], [u'user.id'],
                                            name=u'piece_edit_log_ibfk_3'),
                    sa.PrimaryKeyConstraint('id'),
                    mysql_default_charset=u'utf8',
                    mysql_engine=u'InnoDB')
    op.create_table('piece_source',
                    sa.Column('id',
                              mysql.INTEGER(display_width=11),
                              nullable=False),
                    sa.Column('name', mysql.VARCHAR(length=100),
                              nullable=True),
                    sa.Column('count',
                              mysql.INTEGER(display_width=11),
                              autoincrement=False,
                              nullable=True),
                    sa.Column('created_at', mysql.DATETIME(), nullable=True),
                    sa.PrimaryKeyConstraint('id'),
                    mysql_default_charset=u'utf8',
                    mysql_engine=u'InnoDB')
    op.create_table('mail_log',
                    sa.Column('id',
                              mysql.INTEGER(display_width=11),
                              nullable=False),
                    sa.Column('email',
                              mysql.VARCHAR(length=200),
                              nullable=True),
                    sa.Column('message', mysql.TEXT(), nullable=True),
                    sa.Column('created_at', mysql.DATETIME(), nullable=True),
                    sa.PrimaryKeyConstraint('id'),
                    mysql_default_charset=u'utf8',
                    mysql_engine=u'InnoDB')
    op.create_table('search_log',
                    sa.Column('id',
                              mysql.INTEGER(display_width=11),
                              nullable=False),
                    sa.Column('keyword',
                              mysql.VARCHAR(length=200),
                              nullable=True),
                    sa.Column('created_at', mysql.DATETIME(), nullable=True),
                    sa.Column('user_id',
                              mysql.INTEGER(display_width=11),
                              autoincrement=False,
                              nullable=True),
                    sa.ForeignKeyConstraint(['user_id'], [u'user.id'],
                                            name=u'search_log_ibfk_1'),
                    sa.PrimaryKeyConstraint('id'),
                    mysql_default_charset=u'utf8',
                    mysql_engine=u'InnoDB')
    op.create_table(
        'collection_edit_log_report',
        sa.Column('id', mysql.INTEGER(display_width=11), nullable=False),
        sa.Column('created_at', mysql.DATETIME(), nullable=True),
        sa.Column('user_id',
                  mysql.INTEGER(display_width=11),
                  autoincrement=False,
                  nullable=True),
        sa.Column('log_id',
                  mysql.INTEGER(display_width=11),
                  autoincrement=False,
                  nullable=True),
        sa.Column('processed',
                  mysql.TINYINT(display_width=1),
                  autoincrement=False,
                  nullable=True),
        sa.ForeignKeyConstraint(['log_id'], [u'collection_edit_log.id'],
                                name=u'collection_edit_log_report_ibfk_3'),
        sa.ForeignKeyConstraint(['user_id'], [u'user.id'],
                                name=u'collection_edit_log_report_ibfk_2'),
        sa.PrimaryKeyConstraint('id'),
        mysql_default_charset=u'utf8',
        mysql_engine=u'InnoDB')
    op.create_table(
        'piece_edit_log_report',
        sa.Column('id', mysql.INTEGER(display_width=11), nullable=False),
        sa.Column('created_at', mysql.DATETIME(), nullable=True),
        sa.Column('user_id',
                  mysql.INTEGER(display_width=11),
                  autoincrement=False,
                  nullable=True),
        sa.Column('processed',
                  mysql.TINYINT(display_width=1),
                  autoincrement=False,
                  nullable=True),
        sa.Column('log_id',
                  mysql.INTEGER(display_width=11),
                  autoincrement=False,
                  nullable=True),
        sa.ForeignKeyConstraint(['log_id'], [u'piece_edit_log.id'],
                                name=u'piece_edit_log_report_ibfk_3'),
        sa.ForeignKeyConstraint(['user_id'], [u'user.id'],
                                name=u'piece_edit_log_report_ibfk_2'),
        sa.PrimaryKeyConstraint('id'),
        mysql_default_charset=u'utf8',
        mysql_engine=u'InnoDB')
    op.create_table('sentence',
                    sa.Column('id',
                              mysql.INTEGER(display_width=11),
                              nullable=False),
                    sa.Column('content', mysql.TEXT(), nullable=True),
                    sa.Column('created_at', mysql.DATETIME(), nullable=True),
                    sa.Column('user_id',
                              mysql.INTEGER(display_width=11),
                              autoincrement=False,
                              nullable=True),
                    sa.Column('piece_id',
                              mysql.INTEGER(display_width=11),
                              autoincrement=False,
                              nullable=True),
                    sa.ForeignKeyConstraint(['piece_id'], [u'piece.id'],
                                            name=u'sentence_ibfk_1'),
                    sa.ForeignKeyConstraint(['user_id'], [u'user.id'],
                                            name=u'sentence_ibfk_2'),
                    sa.PrimaryKeyConstraint('id'),
                    mysql_default_charset=u'utf8',
                    mysql_engine=u'InnoDB')
    op.create_table('piece_author',
                    sa.Column('id',
                              mysql.INTEGER(display_width=11),
                              nullable=False),
                    sa.Column('name', mysql.VARCHAR(length=100),
                              nullable=True),
                    sa.Column('count',
                              mysql.INTEGER(display_width=11),
                              autoincrement=False,
                              nullable=True),
                    sa.Column('created_at', mysql.DATETIME(), nullable=True),
                    sa.PrimaryKeyConstraint('id'),
                    mysql_default_charset=u'utf8',
                    mysql_engine=u'InnoDB')
    op.create_table('collection',
                    sa.Column('id',
                              mysql.INTEGER(display_width=11),
                              nullable=False),
                    sa.Column('title',
                              mysql.VARCHAR(length=200),
                              nullable=True),
                    sa.Column('created_at', mysql.DATETIME(), nullable=True),
                    sa.Column('cover',
                              mysql.VARCHAR(length=200),
                              nullable=True),
                    sa.Column('desc', mysql.TEXT(), nullable=True),
                    sa.Column('kind_id',
                              mysql.INTEGER(display_width=11),
                              autoincrement=False,
                              nullable=True),
                    sa.Column('locked',
                              mysql.TINYINT(display_width=1),
                              autoincrement=False,
                              nullable=True),
                    sa.Column('user_id',
                              mysql.INTEGER(display_width=11),
                              autoincrement=False,
                              nullable=True),
                    sa.ForeignKeyConstraint(['kind_id'],
                                            [u'collection_kind.id'],
                                            name=u'collection_ibfk_1'),
                    sa.ForeignKeyConstraint(['user_id'], [u'user.id'],
                                            name=u'collection_ibfk_2'),
                    sa.PrimaryKeyConstraint('id'),
                    mysql_default_charset=u'utf8',
                    mysql_engine=u'InnoDB')
    op.create_table('click_log',
                    sa.Column('id',
                              mysql.INTEGER(display_width=11),
                              nullable=False),
                    sa.Column('url', mysql.VARCHAR(length=100), nullable=True),
                    sa.Column('created_at', mysql.DATETIME(), nullable=True),
                    sa.Column('user_id',
                              mysql.INTEGER(display_width=11),
                              autoincrement=False,
                              nullable=True),
                    sa.ForeignKeyConstraint(['user_id'], [u'user.id'],
                                            name=u'click_log_ibfk_1'),
                    sa.PrimaryKeyConstraint('id'),
                    mysql_default_charset=u'utf8',
                    mysql_engine=u'InnoDB')
    op.create_table('collection_piece',
                    sa.Column('id',
                              mysql.INTEGER(display_width=11),
                              nullable=False),
                    sa.Column('created_at', mysql.DATETIME(), nullable=True),
                    sa.Column('collection_id',
                              mysql.INTEGER(display_width=11),
                              autoincrement=False,
                              nullable=True),
                    sa.Column('piece_id',
                              mysql.INTEGER(display_width=11),
                              autoincrement=False,
                              nullable=True),
                    sa.ForeignKeyConstraint(['collection_id'],
                                            [u'collection.id'],
                                            name=u'collection_piece_ibfk_1'),
                    sa.ForeignKeyConstraint(['piece_id'], [u'piece.id'],
                                            name=u'collection_piece_ibfk_2'),
                    sa.PrimaryKeyConstraint('id'),
                    mysql_default_charset=u'utf8',
                    mysql_engine=u'InnoDB')
Esempio n. 22
0
def upgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    op.alter_column('urltasks',
                    'url',
                    existing_type=mysql.VARCHAR(length=100),
                    nullable=True)
Esempio n. 23
0
def downgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    op.add_column(
        'people',
        sa.Column('firstName', mysql.VARCHAR(length=255), nullable=False))
    op.drop_column('people', 'name')
Esempio n. 24
0
def downgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    op.alter_column('users', 'password_hash',
               existing_type=mysql.VARCHAR(length=128),
               nullable=True)
Esempio n. 25
0
def downgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    op.add_column('media_link', sa.Column('link', mysql.VARCHAR(length=200), nullable=True))
    op.drop_column('media_link', 'url')
    op.drop_column('media_link', 'filename')
Esempio n. 26
0
"""
import sys
import sqlalchemy
import sqlalchemy.orm
import sqlalchemy.ext.declarative
import sqlalchemy.dialects.mysql as mysql

reload(sys)
sys.setdefaultencoding("utf-8")

metadata = sqlalchemy.MetaData()
Video_quality = sqlalchemy.Table(
    "Video_Quality_level",
    metadata,
    sqlalchemy.Column('time', mysql.TIMESTAMP, primary_key=True),
    sqlalchemy.Column('quality_level', mysql.VARCHAR(10), primary_key=True),
    sqlalchemy.Column('imagenum', mysql.BIGINT(10)),
    sqlalchemy.Column('copy_right', mysql.BIGINT(4), primary_key=True),
)


class Video_Quality_level(object):
    """
    video_info
    """
    def __init__(self, time, quality_level, imagenum, copy_right):
        self.time = time
        self.quality_level = quality_level
        self.imagenum = imagenum
        self.copy_right = copy_right
Esempio n. 27
0
def downgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    op.add_column('s_user',
                  sa.Column('like', mysql.VARCHAR(length=30), nullable=True))
def upgrade():
    ### commands auto generated by Alembic - please adjust! ###
    op.create_table(
        'xignite_securty',
        sa.Column('symbol',
                  mysql.VARCHAR(charset='latin1',
                                collation='latin1_swedish_ci',
                                length=20),
                  nullable=False),
        sa.Column('cik',
                  mysql.VARCHAR(charset='latin1',
                                collation='latin1_swedish_ci',
                                length=10),
                  nullable=True),
        sa.Column('cusip',
                  mysql.VARCHAR(charset='latin1',
                                collation='latin1_swedish_ci',
                                length=9),
                  nullable=True),
        sa.Column('isin',
                  mysql.VARCHAR(charset='latin1',
                                collation='latin1_swedish_ci',
                                length=12),
                  nullable=True),
        sa.Column('valoren',
                  mysql.VARCHAR(charset='latin1',
                                collation='latin1_swedish_ci',
                                length=9),
                  nullable=True),
        sa.Column('name', mysql.VARCHAR(length=100), nullable=True),
        sa.Column('market', mysql.VARCHAR(length=20), nullable=True),
        sa.Column('mic',
                  mysql.VARCHAR(charset='latin1',
                                collation='latin1_swedish_ci',
                                length=4),
                  nullable=True),
        sa.Column('most_liquid_exg', sa.BOOLEAN(), nullable=False),
        sa.Column('industry', mysql.VARCHAR(length=100), nullable=True),
        sa.PrimaryKeyConstraint('symbol'))
    op.create_table(
        'xignite_security_release',
        sa.Column('symbol',
                  mysql.VARCHAR(charset='latin1',
                                collation='latin1_swedish_ci',
                                length=20),
                  server_default='',
                  nullable=False),
        sa.Column('title', mysql.VARCHAR(length=500), nullable=True),
        sa.Column('local_pub_date', sa.DATE(), nullable=False),
        sa.Column('utc_offset',
                  sa.FLOAT(),
                  autoincrement=False,
                  nullable=False),
        sa.Column('discovered_at', sa.DATETIME(), nullable=False),
        sa.Column('source', mysql.VARCHAR(length=500), nullable=False),
        sa.Column('url',
                  mysql.VARCHAR(charset='latin1',
                                collation='latin1_swedish_ci',
                                length=767),
                  nullable=False),
        sa.Column('image_urls',
                  mysql.MEDIUMTEXT(convert_unicode=True),
                  nullable=True),
        sa.Column('tags', sa.TEXT(convert_unicode=True), nullable=True),
        sa.Column('proc_dur', sa.FLOAT(), nullable=False),
        sa.ForeignKeyConstraint(['symbol'], [u'xignite_securty.symbol'],
                                name='xignite_security_release_to_security_fk',
                                onupdate='CASCADE',
                                ondelete='CASCADE'),
        sa.PrimaryKeyConstraint('symbol',
                                'local_pub_date',
                                'url',
                                name='xignite_security_release_pk'))
    op.create_table(
        'xignite_security_headline',
        sa.Column('symbol',
                  mysql.VARCHAR(charset='latin1',
                                collation='latin1_swedish_ci',
                                length=20),
                  server_default='',
                  nullable=False),
        sa.Column('title', mysql.VARCHAR(length=500), nullable=True),
        sa.Column('local_pub_date', sa.DATE(), nullable=False),
        sa.Column('utc_offset',
                  sa.FLOAT(),
                  autoincrement=False,
                  nullable=False),
        sa.Column('discovered_at', sa.DATETIME(), nullable=False),
        sa.Column('source', mysql.VARCHAR(length=500), nullable=False),
        sa.Column('url',
                  mysql.VARCHAR(charset='latin1',
                                collation='latin1_swedish_ci',
                                length=767),
                  nullable=False),
        sa.Column('image_urls',
                  mysql.MEDIUMTEXT(convert_unicode=True),
                  nullable=True),
        sa.Column('tags', sa.TEXT(convert_unicode=True), nullable=True),
        sa.Column('proc_dur', sa.FLOAT(), nullable=False),
        sa.ForeignKeyConstraint(
            ['symbol'], [u'xignite_securty.symbol'],
            name='xignite_security_headline_to_security_fk',
            onupdate='CASCADE',
            ondelete='CASCADE'),
        sa.PrimaryKeyConstraint('symbol',
                                'local_pub_date',
                                'url',
                                name='xignite_security_headline_pk'))
Esempio n. 29
0
def downgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    op.add_column('users',
                  sa.Column('date_join', mysql.DATETIME(), nullable=True))
    op.add_column(
        'users',
        sa.Column('human_token', mysql.VARCHAR(length=250), nullable=True))
    op.add_column(
        'users', sa.Column('img_link',
                           mysql.VARCHAR(length=250),
                           nullable=True))
    op.add_column('users',
                  sa.Column('email', mysql.VARCHAR(length=50), nullable=True))
    op.add_column(
        'users',
        sa.Column('is_staff',
                  mysql.TINYINT(display_width=1),
                  autoincrement=False,
                  nullable=True))
    op.add_column(
        'users',
        sa.Column('access_token', mysql.VARCHAR(length=250), nullable=True))
    op.add_column(
        'users', sa.Column('zip_code', mysql.VARCHAR(length=10),
                           nullable=True))
    op.add_column(
        'users',
        sa.Column('display_name', mysql.VARCHAR(length=50), nullable=True))
    op.drop_constraint(None, 'users', type_='unique')
    op.alter_column('users',
                    'user_id',
                    existing_type=sa.Integer(),
                    type_=mysql.VARCHAR(length=50),
                    autoincrement=True)
    op.drop_column('users', 'sex')
    op.drop_column('users', 'firebase_id')
    op.drop_column('users', 'date_birth')
    op.add_column(
        'survey_responses',
        sa.Column('has_symptom_diarrhea',
                  mysql.TINYINT(display_width=1),
                  autoincrement=False,
                  nullable=True))
    op.add_column(
        'survey_responses',
        sa.Column('has_symptom_extreme_fatigue',
                  mysql.TINYINT(display_width=1),
                  autoincrement=False,
                  nullable=True))
    op.add_column(
        'survey_responses',
        sa.Column('history_asthma',
                  mysql.TINYINT(display_width=1),
                  autoincrement=False,
                  nullable=True))
    op.add_column(
        'survey_responses',
        sa.Column('has_symptom_dry_cough',
                  mysql.TINYINT(display_width=1),
                  autoincrement=False,
                  nullable=True))
    op.add_column(
        'survey_responses',
        sa.Column('history_hiv_aids',
                  mysql.TINYINT(display_width=1),
                  autoincrement=False,
                  nullable=True))
    op.add_column(
        'survey_responses',
        sa.Column('has_symptom_abdominal_pain',
                  mysql.TINYINT(display_width=1),
                  autoincrement=False,
                  nullable=True))
    op.add_column(
        'survey_responses',
        sa.Column('has_symptom_no_smell_taste',
                  mysql.TINYINT(display_width=1),
                  autoincrement=False,
                  nullable=True))
    op.add_column(
        'survey_responses',
        sa.Column('feeling_well', mysql.VARCHAR(length=50), nullable=True))
    op.add_column(
        'survey_responses',
        sa.Column('history_liver_disease',
                  mysql.TINYINT(display_width=1),
                  autoincrement=False,
                  nullable=True))
    op.add_column(
        'survey_responses',
        sa.Column('history_diabetes',
                  mysql.TINYINT(display_width=1),
                  autoincrement=False,
                  nullable=True))
    op.add_column(
        'survey_responses',
        sa.Column('history_bmi_over_40',
                  mysql.TINYINT(display_width=1),
                  autoincrement=False,
                  nullable=True))
    op.add_column(
        'survey_responses',
        sa.Column('has_symptom_other',
                  mysql.TINYINT(display_width=1),
                  autoincrement=False,
                  nullable=True))
    op.add_column(
        'survey_responses',
        sa.Column('history_copd_emphysema',
                  mysql.TINYINT(display_width=1),
                  autoincrement=False,
                  nullable=True))
    op.add_column(
        'survey_responses',
        sa.Column('history_chronic_kidney_disease',
                  mysql.TINYINT(display_width=1),
                  autoincrement=False,
                  nullable=True))
    op.add_column(
        'survey_responses',
        sa.Column('has_symptom_sore_throat',
                  mysql.TINYINT(display_width=1),
                  autoincrement=False,
                  nullable=True))
    op.add_column(
        'survey_responses',
        sa.Column('history_cancer',
                  mysql.TINYINT(display_width=1),
                  autoincrement=False,
                  nullable=True))
    op.add_column(
        'survey_responses',
        sa.Column('history_cardiovascular_disease',
                  mysql.TINYINT(display_width=1),
                  autoincrement=False,
                  nullable=True))
    op.add_column(
        'survey_responses',
        sa.Column('datetime_submitted', mysql.DATETIME(), nullable=True))
    op.add_column(
        'survey_responses',
        sa.Column('has_symptom_chills',
                  mysql.TINYINT(display_width=1),
                  autoincrement=False,
                  nullable=True))
    op.add_column(
        'survey_responses',
        sa.Column('has_symptom_pink_eye',
                  mysql.TINYINT(display_width=1),
                  autoincrement=False,
                  nullable=True))
    op.add_column(
        'survey_responses',
        sa.Column('has_symptom_pressure_chest',
                  mysql.TINYINT(display_width=1),
                  autoincrement=False,
                  nullable=True))
    op.add_column(
        'survey_responses',
        sa.Column('has_symptom_nausea_vomiting',
                  mysql.TINYINT(display_width=1),
                  autoincrement=False,
                  nullable=True))
    op.add_column(
        'survey_responses',
        sa.Column('history_high_blood_pressure',
                  mysql.TINYINT(display_width=1),
                  autoincrement=False,
                  nullable=True))
    op.add_column(
        'survey_responses',
        sa.Column('has_symptom_wet_cough',
                  mysql.TINYINT(display_width=1),
                  autoincrement=False,
                  nullable=True))
    op.alter_column('survey_responses',
                    'user_id',
                    existing_type=sa.Integer(),
                    type_=mysql.VARCHAR(length=50),
                    nullable=True)
Esempio n. 30
0
class FileInstance(db.Model, Timestamp):
    """Model for storing files.

    A file instance represents a file on disk. A file instance may be linked
    from many objects, while an object can have one and only one file instance.

    A file instance also records the storage class, size and checksum of the
    file on disk.

    Additionally, a file instance can be read only in case the storage layer
    is not capable of writing to the file (e.g. can typically be used to
    link to files on externally controlled storage).
    """

    __tablename__ = 'files_files'

    id = db.Column(
        UUIDType,
        primary_key=True,
        default=uuid.uuid4,
    )
    """Identifier of file."""

    uri = db.Column(db.Text().with_variant(mysql.VARCHAR(255), 'mysql'),
                    unique=True,
                    nullable=True)
    """Location of file."""

    storage_class = db.Column(db.String(1), nullable=True)
    """Storage class of file."""

    size = db.Column(db.BigInteger, default=0, nullable=True)
    """Size of file."""

    checksum = db.Column(db.String(255), nullable=True)
    """String representing the checksum of the object."""

    readable = db.Column(db.Boolean(name='readable'),
                         default=True,
                         nullable=False)
    """Defines if the file is read only."""

    writable = db.Column(db.Boolean(name='writable'),
                         default=True,
                         nullable=False)
    """Defines if file is writable.

    This property is used to create a file instance prior to having the actual
    file at the given URI. This is useful when e.g. copying a file instance.
    """

    last_check_at = db.Column(db.DateTime, nullable=True)
    """Timestamp of last fixity check."""

    last_check = db.Column(db.Boolean(name='last_check'), default=True)
    """Result of last fixity check."""
    @validates('uri')
    def validate_uri(self, key, uri):
        """Validate uri."""
        if len(uri) > current_app.config['FILES_REST_FILE_URI_MAX_LEN']:
            raise ValueError('FileInstance URI too long ({0}).'.format(
                len(uri)))
        return uri

    @classmethod
    def get(cls, file_id):
        """Get a file instance."""
        return cls.query.filter_by(id=file_id).one_or_none()

    @classmethod
    def get_by_uri(cls, uri):
        """Get a file instance by URI."""
        assert uri is not None
        return cls.query.filter_by(uri=uri).one_or_none()

    @classmethod
    def create(cls):
        """Create a file instance.

        Note, object is only added to the database session.
        """
        obj = cls(
            id=uuid.uuid4(),
            writable=True,
            readable=False,
            size=0,
        )
        db.session.add(obj)
        return obj

    def delete(self):
        """Delete a file instance.

        The file instance can be deleted if it has no references from other
        objects. The caller is responsible to test if the file instance is
        writable and that the disk file can actually be removed.

        .. note::

           Normally you should use the Celery task to delete a file instance,
           as this method will not remove the file on disk.
        """
        self.query.filter_by(id=self.id).delete()
        return self

    def storage(self, **kwargs):
        """Get storage interface for object.

        Uses the applications storage factory to create a storage interface
        that can be used for this particular file instance.

        :returns: Storage interface.
        """
        return current_files_rest.storage_factory(fileinstance=self, **kwargs)

    @ensure_readable()
    def update_checksum(self,
                        progress_callback=None,
                        chunk_size=None,
                        checksum_kwargs=None,
                        **kwargs):
        """Update checksum based on file."""
        self.checksum = self.storage(**kwargs).checksum(
            progress_callback=progress_callback,
            chunk_size=chunk_size,
            **(checksum_kwargs or {}))

    def clear_last_check(self):
        """Clear the checksum of the file."""
        with db.session.begin_nested():
            self.last_check = None
            self.last_check_at = datetime.utcnow()
        return self

    def verify_checksum(self,
                        progress_callback=None,
                        chunk_size=None,
                        throws=True,
                        checksum_kwargs=None,
                        **kwargs):
        """Verify checksum of file instance.

        :param bool throws: If `True`, exceptions raised during checksum
            calculation will be re-raised after logging. If set to `False`, and
            an exception occurs, the `last_check` field is set to `None`
            (`last_check_at` of course is updated), since no check actually was
            performed.
        :param dict checksum_kwargs: Passed as `**kwargs`` to
            ``storage().checksum``.
        """
        try:
            real_checksum = self.storage(**kwargs).checksum(
                progress_callback=progress_callback,
                chunk_size=chunk_size,
                **(checksum_kwargs or {}))
        except Exception as exc:
            current_app.logger.exception(str(exc))
            if throws:
                raise
            real_checksum = None
        with db.session.begin_nested():
            self.last_check = (None if real_checksum is None else
                               (self.checksum == real_checksum))
            self.last_check_at = datetime.utcnow()
        return self.last_check

    @ensure_writable()
    def init_contents(self, size=0, **kwargs):
        """Initialize file."""
        self.set_uri(*self.storage(**kwargs).initialize(size=size),
                     readable=False,
                     writable=True)

    @ensure_writable()
    def update_contents(self,
                        stream,
                        seek=0,
                        size=None,
                        chunk_size=None,
                        progress_callback=None,
                        **kwargs):
        """Save contents of stream to this file.

        :param obj: ObjectVersion instance from where this file is accessed
            from.
        :param stream: File-like stream.
        """
        self.checksum = None
        return self.storage(**kwargs).update(
            stream,
            seek=seek,
            size=size,
            chunk_size=chunk_size,
            progress_callback=progress_callback)

    @ensure_writable()
    def set_contents(self,
                     stream,
                     chunk_size=None,
                     size=None,
                     size_limit=None,
                     progress_callback=None,
                     **kwargs):
        """Save contents of stream to this file.

        :param obj: ObjectVersion instance from where this file is accessed
            from.
        :param stream: File-like stream.
        """
        self.set_uri(*self.storage(
            **kwargs).save(stream,
                           chunk_size=chunk_size,
                           size=size,
                           size_limit=size_limit,
                           progress_callback=progress_callback))

    @ensure_writable()
    def copy_contents(self,
                      fileinstance,
                      progress_callback=None,
                      chunk_size=None,
                      **kwargs):
        """Copy this file instance into another file instance."""
        if not fileinstance.readable:
            raise ValueError('Source file instance is not readable.')
        if not self.size == 0:
            raise ValueError('File instance has data.')

        self.set_uri(*self.storage(
            **kwargs).copy(fileinstance.storage(**kwargs),
                           chunk_size=chunk_size,
                           progress_callback=progress_callback))

    @ensure_readable()
    def send_file(self,
                  filename,
                  restricted=True,
                  mimetype=None,
                  trusted=False,
                  chunk_size=None,
                  as_attachment=False,
                  **kwargs):
        """Send file to client."""
        return self.storage(**kwargs).send_file(
            filename,
            mimetype=mimetype,
            restricted=restricted,
            checksum=self.checksum,
            trusted=trusted,
            chunk_size=chunk_size,
            as_attachment=as_attachment,
        )

    def set_uri(self,
                uri,
                size,
                checksum,
                readable=True,
                writable=False,
                storage_class=None):
        """Set a location of a file."""
        self.uri = uri
        self.size = size
        self.checksum = checksum
        self.writable = writable
        self.readable = readable
        self.storage_class = \
            current_app.config['FILES_REST_DEFAULT_STORAGE_CLASS'] \
            if storage_class is None else \
            storage_class
        return self