test: add draft workflow coverage and sqlite migration helpers
This commit is contained in:
+13
-6
@@ -37,15 +37,22 @@ That means the MariaDB schema is created automatically as long as:
|
||||
- the backend container can reach `mariadb`
|
||||
|
||||
## 4. SQLite to MariaDB migration notes
|
||||
This repo does **not** yet include an automated data migration tool.
|
||||
If you already have real data in SQLite, recommended migration path is:
|
||||
This repo now includes helper tooling to make migration safer:
|
||||
- `deploy/sqlite_export.py` exports the important SQLite tables into JSON
|
||||
- `deploy/sqlite_preview.py` lets you inspect the exported payload quickly
|
||||
|
||||
Suggested migration path:
|
||||
|
||||
1. Stop writes to the app
|
||||
2. Back up SQLite DB file
|
||||
3. Start MariaDB-backed environment on a staging copy
|
||||
4. Export/import the critical tables with a small migration script or one-time tool
|
||||
5. Validate users, companies, jobs, correspondence, attachments metadata
|
||||
6. Switch production `.env` to MariaDB
|
||||
3. Export SQLite data:
|
||||
- `python deploy/sqlite_export.py /path/to/jobtracker.db sqlite-export.json`
|
||||
4. Preview the export:
|
||||
- `python deploy/sqlite_preview.py sqlite-export.json`
|
||||
5. Start MariaDB-backed environment on a staging copy
|
||||
6. Import with a one-time script/manual loader tailored to your production data
|
||||
7. Validate users, companies, jobs, correspondence, attachments metadata
|
||||
8. Switch production `.env` to MariaDB
|
||||
|
||||
## Tables you would likely want to migrate
|
||||
- `AspNetUsers`
|
||||
|
||||
@@ -0,0 +1,39 @@
|
||||
#!/usr/bin/env python3
|
||||
import json
|
||||
import sqlite3
|
||||
import sys
|
||||
from pathlib import Path
|
||||
|
||||
TABLES = [
|
||||
'AspNetUsers',
|
||||
'AspNetRoles',
|
||||
'AspNetUserRoles',
|
||||
'Companies',
|
||||
'JobApplications',
|
||||
'Correspondences',
|
||||
'Attachments',
|
||||
'JobEvents',
|
||||
'GmailConnections',
|
||||
'UserRuleSettings',
|
||||
]
|
||||
|
||||
|
||||
def export_db(sqlite_path: str, output_path: str) -> None:
|
||||
conn = sqlite3.connect(sqlite_path)
|
||||
conn.row_factory = sqlite3.Row
|
||||
payload = {}
|
||||
for table in TABLES:
|
||||
try:
|
||||
rows = conn.execute(f'SELECT * FROM {table}').fetchall()
|
||||
payload[table] = [dict(row) for row in rows]
|
||||
except sqlite3.Error:
|
||||
payload[table] = []
|
||||
Path(output_path).write_text(json.dumps(payload, default=str, indent=2), encoding='utf-8')
|
||||
conn.close()
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
if len(sys.argv) != 3:
|
||||
print('Usage: sqlite_export.py <sqlite-db-path> <output-json>')
|
||||
raise SystemExit(1)
|
||||
export_db(sys.argv[1], sys.argv[2])
|
||||
@@ -0,0 +1,19 @@
|
||||
#!/usr/bin/env python3
|
||||
import json
|
||||
import sys
|
||||
from pathlib import Path
|
||||
|
||||
|
||||
def main(path: str) -> None:
|
||||
payload = json.loads(Path(path).read_text(encoding='utf-8'))
|
||||
for table, rows in payload.items():
|
||||
print(f'-- {table}: {len(rows)} rows')
|
||||
for row in rows[:2]:
|
||||
print(row)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
if len(sys.argv) != 2:
|
||||
print('Usage: sqlite_preview.py <export-json>')
|
||||
raise SystemExit(1)
|
||||
main(sys.argv[1])
|
||||
Reference in New Issue
Block a user