Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 883943d

Browse files
committedFeb 1, 2023
Fix gitpod.yml
1 parent 8f18c12 commit 883943d

File tree

7 files changed

+469
-264
lines changed

7 files changed

+469
-264
lines changed
 

‎.gitpod.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,15 @@ ports:
1111
onOpen: ignore
1212
tasks:
1313
- init: >
14-
(cp -n .env.example .env || true) &&
14+
(touch .env || true) &&
1515
pipenv install &&
1616
psql -U gitpod -c 'CREATE DATABASE example;' &&
1717
psql -U gitpod -c 'CREATE EXTENSION unaccent;' -d example &&
1818
bash database.sh &&
1919
python docs/assets/greeting.py back
2020
- command: >
21-
echo BACKEND_URL=$(gp url 3001) >> .env &&
2221
cat .env.example >> .env &&
22+
echo BACKEND_URL=$(gp url 3001) >> .env &&
2323
npm install &&
2424
python docs/assets/greeting.py front
2525
openMode: split-right

‎Pipfile.lock

+254-262
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎migrations/README

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Single-database configuration for Flask.

‎migrations/alembic.ini

+50
Original file line numberDiff line numberDiff line change
@@ -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

+103
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
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:
23+
# this works with Flask-SQLAlchemy>=3
24+
return current_app.extensions['migrate'].db.engine
25+
26+
27+
# add your model's MetaData object here
28+
# for 'autogenerate' support
29+
# from myapp import mymodel
30+
# target_metadata = mymodel.Base.metadata
31+
config.set_main_option(
32+
'sqlalchemy.url', str(get_engine().url).replace('%', '%%'))
33+
target_db = current_app.extensions['migrate'].db
34+
35+
# other values from the config, defined by the needs of env.py,
36+
# can be acquired:
37+
# my_important_option = config.get_main_option("my_important_option")
38+
# ... etc.
39+
40+
41+
def get_metadata():
42+
if hasattr(target_db, 'metadatas'):
43+
return target_db.metadatas[None]
44+
return target_db.metadata
45+
46+
47+
def run_migrations_offline():
48+
"""Run migrations in 'offline' mode.
49+
50+
This configures the context with just a URL
51+
and not an Engine, though an Engine is acceptable
52+
here as well. By skipping the Engine creation
53+
we don't even need a DBAPI to be available.
54+
55+
Calls to context.execute() here emit the given string to the
56+
script output.
57+
58+
"""
59+
url = config.get_main_option("sqlalchemy.url")
60+
context.configure(
61+
url=url, target_metadata=get_metadata(), literal_binds=True
62+
)
63+
64+
with context.begin_transaction():
65+
context.run_migrations()
66+
67+
68+
def run_migrations_online():
69+
"""Run migrations in 'online' mode.
70+
71+
In this scenario we need to create an Engine
72+
and associate a connection with the context.
73+
74+
"""
75+
76+
# this callback is used to prevent an auto-migration from being generated
77+
# when there are no changes to the schema
78+
# reference: http://alembic.zzzcomputing.com/en/latest/cookbook.html
79+
def process_revision_directives(context, revision, directives):
80+
if getattr(config.cmd_opts, 'autogenerate', False):
81+
script = directives[0]
82+
if script.upgrade_ops.is_empty():
83+
directives[:] = []
84+
logger.info('No changes in schema detected.')
85+
86+
connectable = get_engine()
87+
88+
with connectable.connect() as connection:
89+
context.configure(
90+
connection=connection,
91+
target_metadata=get_metadata(),
92+
process_revision_directives=process_revision_directives,
93+
**current_app.extensions['migrate'].configure_args
94+
)
95+
96+
with context.begin_transaction():
97+
context.run_migrations()
98+
99+
100+
if context.is_offline_mode():
101+
run_migrations_offline()
102+
else:
103+
run_migrations_online()

‎migrations/script.py.mako

+24
Original file line numberDiff line numberDiff line change
@@ -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/4151ae9aa5b8_.py

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
"""empty message
2+
3+
Revision ID: 4151ae9aa5b8
4+
Revises:
5+
Create Date: 2023-02-01 17:19:26.800735
6+
7+
"""
8+
from alembic import op
9+
import sqlalchemy as sa
10+
11+
12+
# revision identifiers, used by Alembic.
13+
revision = '4151ae9aa5b8'
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('user',
22+
sa.Column('id', sa.Integer(), nullable=False),
23+
sa.Column('email', sa.String(length=120), nullable=False),
24+
sa.Column('password', sa.String(length=80), nullable=False),
25+
sa.Column('is_active', sa.Boolean(), nullable=False),
26+
sa.PrimaryKeyConstraint('id'),
27+
sa.UniqueConstraint('email')
28+
)
29+
# ### end Alembic commands ###
30+
31+
32+
def downgrade():
33+
# ### commands auto generated by Alembic - please adjust! ###
34+
op.drop_table('user')
35+
# ### end Alembic commands ###

0 commit comments

Comments
 (0)
Please sign in to comment.