distribusi file model

This commit is contained in:
crunk 2024-04-30 22:16:14 +02:00
parent 48b6e6f211
commit d7ef42dddb
5 changed files with 50 additions and 13 deletions

View File

@ -4,6 +4,7 @@ def deploy():
from app import create_app, db from app import create_app, db
from models.distribusi_model import Distribusis # noqa: F401 from models.distribusi_model import Distribusis # noqa: F401
from models.distribusi_file_model import DistribusiFiles # noqa: F401
# This model is required for flask_migrate to make the table # This model is required for flask_migrate to make the table
from models.user_model import User # noqa: F401 from models.user_model import User # noqa: F401

1
verse/file_crawler.py Normal file
View File

@ -0,0 +1 @@
from models.distribusi_file_model import DistribusiFiles

View File

@ -3,9 +3,10 @@ from __future__ import with_statement
import logging import logging
from logging.config import fileConfig from logging.config import fileConfig
from alembic import context
from flask import current_app from flask import current_app
from alembic import context
# this is the Alembic Config object, which provides # this is the Alembic Config object, which provides
# access to the values within the .ini file in use. # access to the values within the .ini file in use.
config = context.config config = context.config
@ -13,19 +14,17 @@ config = context.config
# Interpret the config file for Python logging. # Interpret the config file for Python logging.
# This line sets up loggers basically. # This line sets up loggers basically.
fileConfig(config.config_file_name) fileConfig(config.config_file_name)
logger = logging.getLogger("alembic.env") logger = logging.getLogger('alembic.env')
# add your model's MetaData object here # add your model's MetaData object here
# for 'autogenerate' support # for 'autogenerate' support
# from myapp import mymodel # from myapp import mymodel
# target_metadata = mymodel.Base.metadata # target_metadata = mymodel.Base.metadata
config.set_main_option( config.set_main_option(
"sqlalchemy.url", 'sqlalchemy.url',
str(current_app.extensions["migrate"].db.get_engine().url).replace( str(current_app.extensions['migrate'].db.get_engine().url).replace(
"%", "%%" '%', '%%'))
), target_metadata = current_app.extensions['migrate'].db.metadata
)
target_metadata = current_app.extensions["migrate"].db.metadata
# other values from the config, defined by the needs of env.py, # other values from the config, defined by the needs of env.py,
# can be acquired: # can be acquired:
@ -66,20 +65,20 @@ def run_migrations_online():
# when there are no changes to the schema # when there are no changes to the schema
# reference: http://alembic.zzzcomputing.com/en/latest/cookbook.html # reference: http://alembic.zzzcomputing.com/en/latest/cookbook.html
def process_revision_directives(context, revision, directives): def process_revision_directives(context, revision, directives):
if getattr(config.cmd_opts, "autogenerate", False): if getattr(config.cmd_opts, 'autogenerate', False):
script = directives[0] script = directives[0]
if script.upgrade_ops.is_empty(): if script.upgrade_ops.is_empty():
directives[:] = [] directives[:] = []
logger.info("No changes in schema detected.") logger.info('No changes in schema detected.')
connectable = current_app.extensions["migrate"].db.get_engine() connectable = current_app.extensions['migrate'].db.get_engine()
with connectable.connect() as connection: with connectable.connect() as connection:
context.configure( context.configure(
connection=connection, connection=connection,
target_metadata=target_metadata, target_metadata=target_metadata,
process_revision_directives=process_revision_directives, process_revision_directives=process_revision_directives,
**current_app.extensions["migrate"].configure_args, **current_app.extensions['migrate'].configure_args
) )
with context.begin_transaction(): with context.begin_transaction():

View File

@ -0,0 +1,36 @@
"""empty message
Revision ID: 8ede45e978d9
Revises:
Create Date: 2024-04-30 22:15:48.023060
"""
from alembic import op
import sqlalchemy as sa
# revision identifiers, used by Alembic.
revision = '8ede45e978d9'
down_revision = None
branch_labels = None
depends_on = None
def upgrade():
# ### commands auto generated by Alembic - please adjust! ###
with op.batch_alter_table('distribusi_files', schema=None) as batch_op:
batch_op.alter_column('type',
existing_type=sa.VARCHAR(length=300),
nullable=True)
# ### end Alembic commands ###
def downgrade():
# ### commands auto generated by Alembic - please adjust! ###
with op.batch_alter_table('distribusi_files', schema=None) as batch_op:
batch_op.alter_column('type',
existing_type=sa.VARCHAR(length=300),
nullable=False)
# ### end Alembic commands ###

View File

@ -7,7 +7,7 @@ class DistribusiFiles(db.Model):
__tablename__ = "distribusi_files" __tablename__ = "distribusi_files"
id = db.Column(db.Integer, primary_key=True) id = db.Column(db.Integer, primary_key=True)
type = db.Column(db.String(300), nullable=False, unique=True) type = db.Column(db.String(300), nullable=True, unique=False)
distribusi = db.Column(db.Integer, db.ForeignKey("distribusis.id")) distribusi = db.Column(db.Integer, db.ForeignKey("distribusis.id"))
path = db.Column(db.String(4096), nullable=True, unique=False) path = db.Column(db.String(4096), nullable=True, unique=False)
description = db.Column(db.String(9), nullable=True, unique=False) description = db.Column(db.String(9), nullable=True, unique=False)