spark-sql-migrations 0.0.4__tar.gz → 0.0.5__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {spark_sql_migrations-0.0.4 → spark_sql_migrations-0.0.5}/PKG-INFO +1 -1
- {spark_sql_migrations-0.0.4 → spark_sql_migrations-0.0.5}/setup.py +1 -1
- {spark_sql_migrations-0.0.4 → spark_sql_migrations-0.0.5}/spark_sql_migrations/spark_sql/spark_sql.py +21 -12
- {spark_sql_migrations-0.0.4 → spark_sql_migrations-0.0.5}/spark_sql_migrations.egg-info/PKG-INFO +1 -1
- {spark_sql_migrations-0.0.4 → spark_sql_migrations-0.0.5}/LICENSE +0 -0
- {spark_sql_migrations-0.0.4 → spark_sql_migrations-0.0.5}/MANIFEST.in +0 -0
- {spark_sql_migrations-0.0.4 → spark_sql_migrations-0.0.5}/backend_shim.py +0 -0
- {spark_sql_migrations-0.0.4 → spark_sql_migrations-0.0.5}/setup.cfg +0 -0
- {spark_sql_migrations-0.0.4 → spark_sql_migrations-0.0.5}/spark_sql_migrations/__init__.py +0 -0
- {spark_sql_migrations-0.0.4 → spark_sql_migrations-0.0.5}/spark_sql_migrations/migration_templates/default_migration_template.sql +0 -0
- {spark_sql_migrations-0.0.4 → spark_sql_migrations-0.0.5}/spark_sql_migrations/migrations_initial/first_01_intial_create_cat_dbr_only.sql +0 -0
- {spark_sql_migrations-0.0.4 → spark_sql_migrations-0.0.5}/spark_sql_migrations/migrations_initial/first_02_intial_create_schema_all.sql +0 -0
- {spark_sql_migrations-0.0.4 → spark_sql_migrations-0.0.5}/spark_sql_migrations/migrations_initial/first_03_intial_create_state_table_all.sql +0 -0
- {spark_sql_migrations-0.0.4 → spark_sql_migrations-0.0.5}/spark_sql_migrations/py.typed +0 -0
- {spark_sql_migrations-0.0.4 → spark_sql_migrations-0.0.5}/spark_sql_migrations/spark_sql/__init__.py +0 -0
- {spark_sql_migrations-0.0.4 → spark_sql_migrations-0.0.5}/spark_sql_migrations/spark_utils.py +0 -0
- {spark_sql_migrations-0.0.4 → spark_sql_migrations-0.0.5}/spark_sql_migrations.egg-info/SOURCES.txt +0 -0
- {spark_sql_migrations-0.0.4 → spark_sql_migrations-0.0.5}/spark_sql_migrations.egg-info/dependency_links.txt +0 -0
- {spark_sql_migrations-0.0.4 → spark_sql_migrations-0.0.5}/spark_sql_migrations.egg-info/entry_points.txt +0 -0
- {spark_sql_migrations-0.0.4 → spark_sql_migrations-0.0.5}/spark_sql_migrations.egg-info/namespace_packages.txt +0 -0
- {spark_sql_migrations-0.0.4 → spark_sql_migrations-0.0.5}/spark_sql_migrations.egg-info/requires.txt +0 -0
- {spark_sql_migrations-0.0.4 → spark_sql_migrations-0.0.5}/spark_sql_migrations.egg-info/top_level.txt +0 -0
|
@@ -150,20 +150,20 @@ def get_migrations_list(migrations_dir):
|
|
|
150
150
|
return get_ordered_migration_objs(migrations)
|
|
151
151
|
|
|
152
152
|
|
|
153
|
+
def get_table_version(spark, migration_type, cat: str, schema: str):
|
|
154
|
+
version_table = f"{cat}.{schema}.{VERSION_TABLE}"
|
|
155
|
+
if not spark.catalog.tableExists(version_table):
|
|
156
|
+
return None
|
|
157
|
+
return spark.read.table(version_table).where(col("migration_type") == migration_type).select("version_num").head()
|
|
158
|
+
|
|
159
|
+
|
|
153
160
|
def get_unapplied_migrations_list(spark, migrations_dir, migration_type, cat: str, schema: str):
|
|
154
161
|
"""the tail of one chain after the revision VERSION_TABLE records for it.
|
|
155
162
|
|
|
156
163
|
the whole chain when the table is missing or holds no row for this type.
|
|
157
164
|
"""
|
|
158
165
|
ordered = get_migrations_list(migrations_dir)
|
|
159
|
-
|
|
160
|
-
version_table = f"{cat}.{schema}.{VERSION_TABLE}"
|
|
161
|
-
if not spark.catalog.tableExists(version_table):
|
|
162
|
-
return ordered
|
|
163
|
-
|
|
164
|
-
current = (
|
|
165
|
-
spark.read.table(version_table).where(col("migration_type") == migration_type).select("version_num").head()
|
|
166
|
-
)
|
|
166
|
+
current = get_table_version(spark, migration_type, cat, schema)
|
|
167
167
|
if not current:
|
|
168
168
|
return ordered
|
|
169
169
|
|
|
@@ -180,9 +180,6 @@ def get_unapplied_migrations_list(spark, migrations_dir, migration_type, cat: st
|
|
|
180
180
|
|
|
181
181
|
|
|
182
182
|
def create_new_migration(message: str, template_path: str, output_path: str, truncate_slug_length: int = 40):
|
|
183
|
-
"""
|
|
184
|
-
TODO XXX start looking up prev revision id from db or files and including it
|
|
185
|
-
"""
|
|
186
183
|
rev_id = uuid.uuid4().hex[-12:]
|
|
187
184
|
|
|
188
185
|
date_prefix = datetime.datetime.today().strftime("%y%m%d")
|
|
@@ -195,8 +192,15 @@ def create_new_migration(message: str, template_path: str, output_path: str, tru
|
|
|
195
192
|
|
|
196
193
|
migration_path = os.path.join(output_path, migration_filename)
|
|
197
194
|
|
|
195
|
+
try:
|
|
196
|
+
ordered_migrations = get_migrations_list(output_path)
|
|
197
|
+
last_migration_rev_id = ordered_migrations[-1].revision_id if len(ordered_migrations) > 0 else ""
|
|
198
|
+
except ValueError:
|
|
199
|
+
last_migration_rev_id = ""
|
|
200
|
+
|
|
198
201
|
default_migration_content = open(template_path).read()
|
|
199
202
|
default_migration_content = default_migration_content.replace("{{revision_id}}", rev_id)
|
|
203
|
+
default_migration_content = default_migration_content.replace("{{prev_revision_id}}", last_migration_rev_id)
|
|
200
204
|
|
|
201
205
|
with open(migration_path, "w") as migration_file:
|
|
202
206
|
migration_file.write(default_migration_content)
|
|
@@ -327,7 +331,12 @@ def build_parser(): # pragma: no cover
|
|
|
327
331
|
|
|
328
332
|
p_create = subparsers.add_parser("create_new_migration", help="create a new migration from the template")
|
|
329
333
|
p_create.add_argument("--message", required=True)
|
|
330
|
-
p_create.add_argument(
|
|
334
|
+
p_create.add_argument(
|
|
335
|
+
"--output-path",
|
|
336
|
+
required=True,
|
|
337
|
+
help="the chain directory to write the new migration into. if sql files are in there, the last sql's rev_id"
|
|
338
|
+
"will be set as the new migrations prev_rev_id.",
|
|
339
|
+
)
|
|
331
340
|
p_create.add_argument("--template-path", default=None, help="defaults to the template shipped in this package")
|
|
332
341
|
p_create.set_defaults(func=_cli_create_new_migration)
|
|
333
342
|
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{spark_sql_migrations-0.0.4 → spark_sql_migrations-0.0.5}/spark_sql_migrations/spark_sql/__init__.py
RENAMED
|
File without changes
|
{spark_sql_migrations-0.0.4 → spark_sql_migrations-0.0.5}/spark_sql_migrations/spark_utils.py
RENAMED
|
File without changes
|
{spark_sql_migrations-0.0.4 → spark_sql_migrations-0.0.5}/spark_sql_migrations.egg-info/SOURCES.txt
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{spark_sql_migrations-0.0.4 → spark_sql_migrations-0.0.5}/spark_sql_migrations.egg-info/requires.txt
RENAMED
|
File without changes
|
|
File without changes
|