Skip to content

Commit 197c438

Browse files
committed
doc
1 parent 822ba80 commit 197c438

File tree

2 files changed

+26
-1
lines changed

2 files changed

+26
-1
lines changed

CONTRIBUTING.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,18 @@ After the initial production release of Qiita, changes to the database schema wi
9494
2. We keep fully patched versions of the DBS and HTML files in the repository
9595
3. We keep a patch file for each patch as required in the `qiita_db/support_files/patches` directory. Note that **the patches will be applied in order based on the natural sort order of their filename** (e.g., `2.sql` will be applied before `10.sql`, and `10.sql` will be applied before `a.sql`)
9696

97+
### Patch 91.sql
98+
99+
In May 2024 we decided to:
100+
* Merge all patches into the main database, this means that there are no patches younger than 92.sql.
101+
* Not allow INSERT/UPDATE queries within the main *.sql patches, to minimize the possibility of unnexpected changes.
102+
* Added a new folder `patches/test_db_sql/` where we can store sql files that will only be applied for the test environment.
103+
104+
Note that these changes mean:
105+
1. 92.sql is the current first sql file to patch the database.
106+
2. If you need to make changes to both the production and tests database you will need to use the *.py.
107+
3. If you need to make changes _only_ to the tests database you need to add a patch to `patches/test_db_sql/`.
108+
97109
### Developer Workflow
98110

99111
1. Load the fully patched DBS file (e.g., `qiita-db.dbs`) in [DBSchema](http://www.dbschema.com/)

qiita_db/environment_manager.py

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -397,6 +397,7 @@ def patch(patches_dir=PATCHES_DIR, verbose=False, test=False):
397397
with qdb.sql_connection.TRN:
398398
_populate_test_db()
399399

400+
not_allowed_matches = ["insert", "update"]
400401
patch_update_sql = "UPDATE settings SET current_patch = %s"
401402
for sql_patch_fp in sql_patch_files[next_patch_index:]:
402403
sql_patch_filename = basename(sql_patch_fp)
@@ -410,7 +411,19 @@ def patch(patches_dir=PATCHES_DIR, verbose=False, test=False):
410411
if verbose:
411412
print('\tApplying patch %s...' % sql_patch_filename)
412413

413-
qdb.sql_connection.TRN.add(patch_file.read())
414+
sql = patch_file.read()
415+
sql_test = any([m in l
416+
for l in sql.split('\n')
417+
if not l.startswith('--')
418+
for m in not_allowed_matches])
419+
if sql_test:
420+
msg = (
421+
f"Patch '{basename(sql_patch_fp)}' has an invalid "
422+
f"'match {not_allowed_matches}'; please move them a "
423+
f"test patch.\n*********{sql}\n*********")
424+
raise ValueError(msg)
425+
426+
qdb.sql_connection.TRN.add(sql)
414427
qdb.sql_connection.TRN.add(
415428
patch_update_sql, [sql_patch_filename])
416429

0 commit comments

Comments
 (0)