Skip to content

Commit 6e4a8d7

Browse files
authored
Merge pull request #38 from cloudera/upgrade
Upgrade
2 parents a7430a5 + 36114fa commit 6e4a8d7

File tree

14 files changed

+980
-3
lines changed

14 files changed

+980
-3
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,3 +66,6 @@ htmlcov/
6666
coverage.xml
6767
.tox/
6868
.nox/
69+
.pytest_cache
70+
#old code
71+
app/frontend

.project-metadata.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11

2-
name: Synthetic Data Generation
2+
name: Synthetic Data Studio
33
description: |
44
This AMP demonstrates how we can generate synthetic data for finetuning, ground truth for LLM use case evaluation, embedding finetuning etc.
55

alembic.ini

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
# A generic, single database configuration.
2+
3+
[alembic]
4+
# path to migration scripts
5+
script_location = alembic
6+
7+
# template used to generate migration files
8+
# file_template = %%(rev)s_%%(slug)s
9+
10+
# sys.path path, will be prepended to sys.path if present.
11+
# defaults to the current working directory.
12+
prepend_sys_path = .
13+
14+
# timezone to use when rendering the date within the migration file
15+
# as well as the filename.
16+
# If specified, requires the python-dateutil library that can be
17+
# installed by adding `alembic[tz]` to the pip requirements
18+
# string value is passed to dateutil.tz.gettz()
19+
# leave blank for localtime
20+
# timezone =
21+
22+
# max length of characters to apply to the
23+
# "slug" field
24+
# truncate_slug_length = 40
25+
26+
# set to 'true' to run the environment during
27+
# the 'revision' command, regardless of autogenerate
28+
# revision_environment = false
29+
30+
# set to 'true' to allow .pyc and .pyo files without
31+
# a source .py file to be detected as revisions in the
32+
# versions/ directory
33+
# sourceless = false
34+
35+
# version location specification; This defaults
36+
# to alembic/versions. When using multiple version
37+
# directories, initial revisions must be specified with --version-path.
38+
# The path separator used here should be the separator specified by "version_path_separator" below.
39+
# version_locations = %(here)s/bar:%(here)s/bat:alembic/versions
40+
41+
# version path separator; As mentioned above, this is the character used to split
42+
# version_locations. The default within new alembic.ini files is "os", which uses os.pathsep.
43+
# If this key is omitted entirely, it falls back to the legacy behavior of splitting on spaces and/or commas.
44+
# Valid values for version_path_separator are:
45+
#
46+
# version_path_separator = :
47+
# version_path_separator = ;
48+
# version_path_separator = space
49+
50+
# set to 'true' to search source directory for include files
51+
# that are relative to the alembic.ini file
52+
# source_include_current_dir = true
53+
54+
# version file pattern
55+
# version_file_pattern = %(rev)s_%%(slug)s
56+
57+
# Logging configuration
58+
[loggers]
59+
keys = root,sqlalchemy,alembic
60+
61+
[handlers]
62+
keys = console
63+
64+
[formatters]
65+
keys = generic
66+
67+
[logger_root]
68+
level = WARN
69+
handlers = console
70+
qualname =
71+
72+
[logger_sqlalchemy]
73+
level = WARN
74+
handlers =
75+
qualname = sqlalchemy.engine
76+
77+
[logger_alembic]
78+
level = INFO
79+
handlers =
80+
qualname = alembic
81+
82+
[handler_console]
83+
class = StreamHandler
84+
args = (sys.stderr,)
85+
level = NOTSET
86+
formatter = generic
87+
88+
[formatter_generic]
89+
format = %(levelname)-5.5s [%(name)s] %(message)s
90+
datefmt = %H:%M:%S

alembic/README

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Generic single-database configuration.

alembic/env.py

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
# alembic/env.py
2+
from logging.config import fileConfig
3+
from sqlalchemy import engine_from_config, pool
4+
from alembic import context
5+
import os
6+
import sys
7+
from pathlib import Path
8+
9+
# This is needed to find the app module
10+
base_path = Path(__file__).parent.parent
11+
sys.path.append(str(base_path))
12+
13+
from app.migrations.alembic_schema_models import Base
14+
15+
# this is the Alembic Config object
16+
config = context.config
17+
18+
# Interpret the config file for Python logging
19+
if config.config_file_name is not None:
20+
fileConfig(config.config_file_name)
21+
22+
# Get database path (one level up from app directory)
23+
db_path = os.path.join(base_path, "metadata.db")
24+
config.set_main_option("sqlalchemy.url", f"sqlite:///{db_path}")
25+
26+
target_metadata = Base.metadata
27+
28+
def run_migrations_offline() -> None:
29+
url = config.get_main_option("sqlalchemy.url")
30+
context.configure(
31+
url=url,
32+
target_metadata=target_metadata,
33+
literal_binds=True,
34+
dialect_opts={"paramstyle": "named"},
35+
)
36+
37+
with context.begin_transaction():
38+
context.run_migrations()
39+
40+
def run_migrations_online() -> None:
41+
connectable = engine_from_config(
42+
config.get_section(config.config_ini_section, {}),
43+
prefix="sqlalchemy.",
44+
poolclass=pool.NullPool,
45+
)
46+
47+
with connectable.connect() as connection:
48+
context.configure(
49+
connection=connection,
50+
target_metadata=target_metadata,
51+
render_as_batch=True
52+
)
53+
54+
with context.begin_transaction():
55+
context.run_migrations()
56+
57+
if context.is_offline_mode():
58+
run_migrations_offline()
59+
else:
60+
run_migrations_online()

alembic/script.py.mako

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
"""${message}
2+
3+
Revision ID: ${up_revision}
4+
Revises: ${down_revision | comma,n}
5+
Create Date: ${create_date}
6+
7+
"""
8+
from typing import Sequence, Union
9+
10+
from alembic import op
11+
import sqlalchemy as sa
12+
${imports if imports else ""}
13+
14+
# revision identifiers, used by Alembic.
15+
revision: str = ${repr(up_revision)}
16+
down_revision: Union[str, None] = ${repr(down_revision)}
17+
branch_labels: Union[str, Sequence[str], None] = ${repr(branch_labels)}
18+
depends_on: Union[str, Sequence[str], None] = ${repr(depends_on)}
19+
20+
21+
def upgrade() -> None:
22+
${upgrades if upgrades else "pass"}
23+
24+
25+
def downgrade() -> None:
26+
${downgrades if downgrades else "pass"}

0 commit comments

Comments
 (0)