-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
replace migration system with db erasure
- Loading branch information
Showing
10 changed files
with
66 additions
and
73 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -31,7 +31,6 @@ | |
fuse | ||
mutagen | ||
uuid6-python | ||
yoyo-migrations | ||
]; | ||
dev-deps = with python.pkgs; [ | ||
black | ||
|
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,34 +1,31 @@ | ||
import sqlite3 | ||
from pathlib import Path | ||
import hashlib | ||
|
||
import yoyo | ||
from rose.cache.database import connect, migrate_database | ||
from rose.foundation.conf import SCHEMA_PATH, Config | ||
|
||
from conftest import freeze_database_time | ||
from rose.cache.database import migrate_database | ||
from rose.foundation.conf import MIGRATIONS_PATH, Config | ||
|
||
|
||
def test_run_database_migrations(config: Config) -> None: | ||
def test_schema(config: Config) -> None: | ||
# Test that the schema successfully bootstraps. | ||
with SCHEMA_PATH.open("rb") as fp: | ||
latest_schema_hash = hashlib.sha256(fp.read()).hexdigest() | ||
migrate_database(config) | ||
assert config.cache_database_path.exists() | ||
|
||
with sqlite3.connect(str(config.cache_database_path)) as conn: | ||
freeze_database_time(conn) | ||
cursor = conn.execute("SELECT 1 FROM _yoyo_version") | ||
assert len(cursor.fetchall()) > 0 | ||
with connect(config) as conn: | ||
cursor = conn.execute("SELECT value FROM _schema_hash") | ||
assert cursor.fetchone()[0] == latest_schema_hash | ||
|
||
|
||
def test_migrations(isolated_dir: Path) -> None: | ||
""" | ||
Test that, for each migration, the up -> down -> up path doesn't | ||
cause an error. Basically, ladder our way up through the migration | ||
chain. | ||
""" | ||
backend = yoyo.get_backend(f"sqlite:///{isolated_dir / 'db.sqlite3'}") | ||
migrations = yoyo.read_migrations(str(MIGRATIONS_PATH)) | ||
def test_migration(config: Config) -> None: | ||
# Test that "migrating" the database correctly migrates it. | ||
config.cache_database_path.unlink() | ||
with connect(config) as conn: | ||
conn.execute("CREATE TABLE _schema_hash (value TEXT PRIMARY KEY)") | ||
conn.execute("INSERT INTO _schema_hash (value) VALUES ('haha')") | ||
|
||
assert len(migrations) > 0 | ||
for mig in migrations: | ||
backend.apply_one(mig) | ||
backend.rollback_one(mig) | ||
backend.apply_one(mig) | ||
with SCHEMA_PATH.open("rb") as fp: | ||
latest_schema_hash = hashlib.sha256(fp.read()).hexdigest() | ||
migrate_database(config) | ||
with connect(config) as conn: | ||
cursor = conn.execute("SELECT value FROM _schema_hash") | ||
assert cursor.fetchone()[0] == latest_schema_hash | ||
cursor = conn.execute("SELECT COUNT(*) FROM _schema_hash") | ||
assert cursor.fetchone()[0] == 1 |
3 changes: 0 additions & 3 deletions
3
migrations/20231009_01_qlEHa-bootstrap.sql → rose/cache/schema.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,6 +14,5 @@ | |
"fuse-python", | ||
"mutagen", | ||
"uuid6-python", | ||
"yoyo-migrations", | ||
], | ||
) |