yasserrmd commited on
Commit
32b4281
·
verified ·
1 Parent(s): c878f7e

Upload 9 files

Browse files
migrations/README ADDED
@@ -0,0 +1 @@
 
 
1
+ Single-database configuration for Flask.
migrations/__pycache__/env.cpython-310.pyc ADDED
Binary file (2.8 kB). View file
 
migrations/__pycache__/env.cpython-311.pyc ADDED
Binary file (5.1 kB). View file
 
migrations/alembic.ini ADDED
@@ -0,0 +1,50 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # A generic, single database configuration.
2
+
3
+ [alembic]
4
+ # template used to generate migration files
5
+ # file_template = %%(rev)s_%%(slug)s
6
+
7
+ # set to 'true' to run the environment during
8
+ # the 'revision' command, regardless of autogenerate
9
+ # revision_environment = false
10
+
11
+
12
+ # Logging configuration
13
+ [loggers]
14
+ keys = root,sqlalchemy,alembic,flask_migrate
15
+
16
+ [handlers]
17
+ keys = console
18
+
19
+ [formatters]
20
+ keys = generic
21
+
22
+ [logger_root]
23
+ level = WARN
24
+ handlers = console
25
+ qualname =
26
+
27
+ [logger_sqlalchemy]
28
+ level = WARN
29
+ handlers =
30
+ qualname = sqlalchemy.engine
31
+
32
+ [logger_alembic]
33
+ level = INFO
34
+ handlers =
35
+ qualname = alembic
36
+
37
+ [logger_flask_migrate]
38
+ level = INFO
39
+ handlers =
40
+ qualname = flask_migrate
41
+
42
+ [handler_console]
43
+ class = StreamHandler
44
+ args = (sys.stderr,)
45
+ level = NOTSET
46
+ formatter = generic
47
+
48
+ [formatter_generic]
49
+ format = %(levelname)-5.5s [%(name)s] %(message)s
50
+ datefmt = %H:%M:%S
migrations/env.py ADDED
@@ -0,0 +1,113 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import logging
2
+ from logging.config import fileConfig
3
+
4
+ from flask import current_app
5
+
6
+ from alembic import context
7
+
8
+ # this is the Alembic Config object, which provides
9
+ # access to the values within the .ini file in use.
10
+ config = context.config
11
+
12
+ # Interpret the config file for Python logging.
13
+ # This line sets up loggers basically.
14
+ fileConfig(config.config_file_name)
15
+ logger = logging.getLogger('alembic.env')
16
+
17
+
18
+ def get_engine():
19
+ try:
20
+ # this works with Flask-SQLAlchemy<3 and Alchemical
21
+ return current_app.extensions['migrate'].db.get_engine()
22
+ except (TypeError, AttributeError):
23
+ # this works with Flask-SQLAlchemy>=3
24
+ return current_app.extensions['migrate'].db.engine
25
+
26
+
27
+ def get_engine_url():
28
+ try:
29
+ return get_engine().url.render_as_string(hide_password=False).replace(
30
+ '%', '%%')
31
+ except AttributeError:
32
+ return str(get_engine().url).replace('%', '%%')
33
+
34
+
35
+ # add your model's MetaData object here
36
+ # for 'autogenerate' support
37
+ # from myapp import mymodel
38
+ # target_metadata = mymodel.Base.metadata
39
+ config.set_main_option('sqlalchemy.url', get_engine_url())
40
+ target_db = current_app.extensions['migrate'].db
41
+
42
+ # other values from the config, defined by the needs of env.py,
43
+ # can be acquired:
44
+ # my_important_option = config.get_main_option("my_important_option")
45
+ # ... etc.
46
+
47
+
48
+ def get_metadata():
49
+ if hasattr(target_db, 'metadatas'):
50
+ return target_db.metadatas[None]
51
+ return target_db.metadata
52
+
53
+
54
+ def run_migrations_offline():
55
+ """Run migrations in 'offline' mode.
56
+
57
+ This configures the context with just a URL
58
+ and not an Engine, though an Engine is acceptable
59
+ here as well. By skipping the Engine creation
60
+ we don't even need a DBAPI to be available.
61
+
62
+ Calls to context.execute() here emit the given string to the
63
+ script output.
64
+
65
+ """
66
+ url = config.get_main_option("sqlalchemy.url")
67
+ context.configure(
68
+ url=url, target_metadata=get_metadata(), literal_binds=True
69
+ )
70
+
71
+ with context.begin_transaction():
72
+ context.run_migrations()
73
+
74
+
75
+ def run_migrations_online():
76
+ """Run migrations in 'online' mode.
77
+
78
+ In this scenario we need to create an Engine
79
+ and associate a connection with the context.
80
+
81
+ """
82
+
83
+ # this callback is used to prevent an auto-migration from being generated
84
+ # when there are no changes to the schema
85
+ # reference: http://alembic.zzzcomputing.com/en/latest/cookbook.html
86
+ def process_revision_directives(context, revision, directives):
87
+ if getattr(config.cmd_opts, 'autogenerate', False):
88
+ script = directives[0]
89
+ if script.upgrade_ops.is_empty():
90
+ directives[:] = []
91
+ logger.info('No changes in schema detected.')
92
+
93
+ conf_args = current_app.extensions['migrate'].configure_args
94
+ if conf_args.get("process_revision_directives") is None:
95
+ conf_args["process_revision_directives"] = process_revision_directives
96
+
97
+ connectable = get_engine()
98
+
99
+ with connectable.connect() as connection:
100
+ context.configure(
101
+ connection=connection,
102
+ target_metadata=get_metadata(),
103
+ **conf_args
104
+ )
105
+
106
+ with context.begin_transaction():
107
+ context.run_migrations()
108
+
109
+
110
+ if context.is_offline_mode():
111
+ run_migrations_offline()
112
+ else:
113
+ run_migrations_online()
migrations/script.py.mako ADDED
@@ -0,0 +1,24 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """${message}
2
+
3
+ Revision ID: ${up_revision}
4
+ Revises: ${down_revision | comma,n}
5
+ Create Date: ${create_date}
6
+
7
+ """
8
+ from alembic import op
9
+ import sqlalchemy as sa
10
+ ${imports if imports else ""}
11
+
12
+ # revision identifiers, used by Alembic.
13
+ revision = ${repr(up_revision)}
14
+ down_revision = ${repr(down_revision)}
15
+ branch_labels = ${repr(branch_labels)}
16
+ depends_on = ${repr(depends_on)}
17
+
18
+
19
+ def upgrade():
20
+ ${upgrades if upgrades else "pass"}
21
+
22
+
23
+ def downgrade():
24
+ ${downgrades if downgrades else "pass"}
migrations/versions/__pycache__/ce4a7e381942_initial_migration_with_all_models.cpython-310.pyc ADDED
Binary file (3.81 kB). View file
 
migrations/versions/__pycache__/ce4a7e381942_initial_migration_with_all_models.cpython-311.pyc ADDED
Binary file (12 kB). View file
 
migrations/versions/ce4a7e381942_initial_migration_with_all_models.py ADDED
@@ -0,0 +1,149 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """Initial migration with all models
2
+
3
+ Revision ID: ce4a7e381942
4
+ Revises:
5
+ Create Date: 2025-04-29 13:27:08.356393
6
+
7
+ """
8
+ from alembic import op
9
+ import sqlalchemy as sa
10
+
11
+
12
+ # revision identifiers, used by Alembic.
13
+ revision = 'ce4a7e381942'
14
+ down_revision = None
15
+ branch_labels = None
16
+ depends_on = None
17
+
18
+
19
+ def upgrade():
20
+ # ### commands auto generated by Alembic - please adjust! ###
21
+ op.create_table('legislation',
22
+ sa.Column('id', sa.Integer(), nullable=False),
23
+ sa.Column('title', sa.String(), nullable=False),
24
+ sa.Column('full_text', sa.Text(), nullable=True),
25
+ sa.Column('jurisdiction', sa.String(), nullable=True),
26
+ sa.Column('type', sa.String(), nullable=True),
27
+ sa.Column('status', sa.String(), nullable=True),
28
+ sa.Column('effective_date', sa.Date(), nullable=True),
29
+ sa.Column('enactment_date', sa.Date(), nullable=True),
30
+ sa.Column('source_url', sa.String(), nullable=True),
31
+ sa.Column('last_updated', sa.DateTime(), nullable=True),
32
+ sa.Column('created_at', sa.DateTime(), nullable=True),
33
+ sa.PrimaryKeyConstraint('id')
34
+ )
35
+ op.create_table('monitoring_sources',
36
+ sa.Column('id', sa.Integer(), nullable=False),
37
+ sa.Column('name', sa.String(), nullable=False),
38
+ sa.Column('url', sa.String(), nullable=False),
39
+ sa.Column('type', sa.String(), nullable=False),
40
+ sa.Column('frequency_minutes', sa.Integer(), nullable=True),
41
+ sa.Column('last_checked', sa.DateTime(), nullable=True),
42
+ sa.Column('is_active', sa.Boolean(), nullable=True),
43
+ sa.Column('created_at', sa.DateTime(), nullable=True),
44
+ sa.PrimaryKeyConstraint('id'),
45
+ sa.UniqueConstraint('url')
46
+ )
47
+ op.create_table('users',
48
+ sa.Column('id', sa.Integer(), nullable=False),
49
+ sa.Column('username', sa.String(length=80), nullable=False),
50
+ sa.Column('password_hash', sa.String(length=128), nullable=False),
51
+ sa.Column('full_name', sa.String(length=120), nullable=True),
52
+ sa.Column('role', sa.String(length=80), nullable=True),
53
+ sa.Column('created_at', sa.DateTime(), nullable=True),
54
+ sa.PrimaryKeyConstraint('id'),
55
+ sa.UniqueConstraint('username')
56
+ )
57
+ op.create_table('amendments',
58
+ sa.Column('id', sa.Integer(), nullable=False),
59
+ sa.Column('legislation_id', sa.Integer(), nullable=False),
60
+ sa.Column('proposed_changes', sa.Text(), nullable=False),
61
+ sa.Column('rationale', sa.Text(), nullable=True),
62
+ sa.Column('status', sa.String(), nullable=True),
63
+ sa.Column('author_id', sa.Integer(), nullable=True),
64
+ sa.Column('created_at', sa.DateTime(), nullable=True),
65
+ sa.Column('last_updated', sa.DateTime(), nullable=True),
66
+ sa.ForeignKeyConstraint(['author_id'], ['users.id'], ),
67
+ sa.ForeignKeyConstraint(['legislation_id'], ['legislation.id'], ),
68
+ sa.PrimaryKeyConstraint('id')
69
+ )
70
+ op.create_table('cross_references',
71
+ sa.Column('id', sa.Integer(), nullable=False),
72
+ sa.Column('source_legislation_id', sa.Integer(), nullable=False),
73
+ sa.Column('target_legislation_id', sa.Integer(), nullable=False),
74
+ sa.Column('relationship_type', sa.String(), nullable=False),
75
+ sa.Column('details', sa.Text(), nullable=True),
76
+ sa.Column('identified_at', sa.DateTime(), nullable=True),
77
+ sa.ForeignKeyConstraint(['source_legislation_id'], ['legislation.id'], ),
78
+ sa.ForeignKeyConstraint(['target_legislation_id'], ['legislation.id'], ),
79
+ sa.PrimaryKeyConstraint('id'),
80
+ sa.UniqueConstraint('source_legislation_id', 'target_legislation_id', 'relationship_type', name='_source_target_rel_uc')
81
+ )
82
+ op.create_table('drafts',
83
+ sa.Column('id', sa.Integer(), nullable=False),
84
+ sa.Column('title', sa.String(), nullable=False),
85
+ sa.Column('content', sa.Text(), nullable=True),
86
+ sa.Column('policy_intent', sa.Text(), nullable=True),
87
+ sa.Column('status', sa.String(), nullable=True),
88
+ sa.Column('author_id', sa.Integer(), nullable=True),
89
+ sa.Column('related_legislation_id', sa.Integer(), nullable=True),
90
+ sa.Column('created_at', sa.DateTime(), nullable=True),
91
+ sa.Column('last_updated', sa.DateTime(), nullable=True),
92
+ sa.ForeignKeyConstraint(['author_id'], ['users.id'], ),
93
+ sa.ForeignKeyConstraint(['related_legislation_id'], ['legislation.id'], ),
94
+ sa.PrimaryKeyConstraint('id')
95
+ )
96
+ op.create_table('impact_analyses',
97
+ sa.Column('id', sa.Integer(), nullable=False),
98
+ sa.Column('document_id', sa.Integer(), nullable=False),
99
+ sa.Column('document_type', sa.String(), nullable=False),
100
+ sa.Column('analysis_type', sa.String(), nullable=False),
101
+ sa.Column('predicted_impact', sa.Text(), nullable=True),
102
+ sa.Column('confidence_score', sa.Float(), nullable=True),
103
+ sa.Column('rationale', sa.Text(), nullable=True),
104
+ sa.Column('generated_by_user_id', sa.Integer(), nullable=True),
105
+ sa.Column('generated_at', sa.DateTime(), nullable=True),
106
+ sa.ForeignKeyConstraint(['generated_by_user_id'], ['users.id'], ),
107
+ sa.PrimaryKeyConstraint('id')
108
+ )
109
+ op.create_table('monitored_events',
110
+ sa.Column('id', sa.Integer(), nullable=False),
111
+ sa.Column('source_id', sa.Integer(), nullable=False),
112
+ sa.Column('detected_at', sa.DateTime(), nullable=True),
113
+ sa.Column('event_summary', sa.Text(), nullable=False),
114
+ sa.Column('event_details', sa.Text(), nullable=True),
115
+ sa.Column('relevance_score', sa.Float(), nullable=True),
116
+ sa.Column('related_legislation_id', sa.Integer(), nullable=True),
117
+ sa.Column('status', sa.String(), nullable=True),
118
+ sa.ForeignKeyConstraint(['related_legislation_id'], ['legislation.id'], ),
119
+ sa.ForeignKeyConstraint(['source_id'], ['monitoring_sources.id'], ),
120
+ sa.PrimaryKeyConstraint('id')
121
+ )
122
+ op.create_table('recommendations',
123
+ sa.Column('id', sa.Integer(), nullable=False),
124
+ sa.Column('related_legislation_id', sa.Integer(), nullable=True),
125
+ sa.Column('recommendation_type', sa.String(), nullable=False),
126
+ sa.Column('recommendation_text', sa.Text(), nullable=False),
127
+ sa.Column('rationale', sa.Text(), nullable=True),
128
+ sa.Column('source_event_id', sa.Integer(), nullable=True),
129
+ sa.Column('status', sa.String(), nullable=True),
130
+ sa.Column('generated_at', sa.DateTime(), nullable=True),
131
+ sa.ForeignKeyConstraint(['related_legislation_id'], ['legislation.id'], ),
132
+ sa.ForeignKeyConstraint(['source_event_id'], ['monitored_events.id'], ),
133
+ sa.PrimaryKeyConstraint('id')
134
+ )
135
+ # ### end Alembic commands ###
136
+
137
+
138
+ def downgrade():
139
+ # ### commands auto generated by Alembic - please adjust! ###
140
+ op.drop_table('recommendations')
141
+ op.drop_table('monitored_events')
142
+ op.drop_table('impact_analyses')
143
+ op.drop_table('drafts')
144
+ op.drop_table('cross_references')
145
+ op.drop_table('amendments')
146
+ op.drop_table('users')
147
+ op.drop_table('monitoring_sources')
148
+ op.drop_table('legislation')
149
+ # ### end Alembic commands ###