Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

adding test_db_sql #3405

Merged
merged 39 commits into from
May 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
57d1b14
Update CHANGELOG.md
antgonza Jan 29, 2024
13eafdf
fix CHANGELOG.md CONFLICT
antgonza Feb 27, 2024
ee98f64
Merge branch 'dev' of github.com:biocore/qiita into dev
antgonza Apr 16, 2024
c3ce6a4
Merge branch 'dev' of github.com:biocore/qiita into dev
antgonza Apr 21, 2024
6767990
Merge branch 'dev' of github.com:biocore/qiita into dev
antgonza Apr 23, 2024
3c1f71b
Merge branch 'dev' of github.com:biocore/qiita into dev
antgonza Apr 26, 2024
8edd0c8
Merge branch 'dev' of github.com:biocore/qiita into dev
antgonza Apr 26, 2024
c98b32e
clean plugins
antgonza May 6, 2024
61687eb
patch 54.sql
antgonza May 6, 2024
47fc3d5
fix Internal Qiita jobs
antgonza May 6, 2024
e88bf83
sample_template.generate_files
antgonza May 6, 2024
ed96bc4
rm extra filepath
antgonza May 6, 2024
e18a8f2
qiita.filepath_filepath_id_seq
antgonza May 6, 2024
0d18fdd
basedir_len
antgonza May 6, 2024
63a573a
basedir_len * 2
antgonza May 6, 2024
72a391b
basedir_len * 3
antgonza May 7, 2024
5542328
get_db_files_base_dir
antgonza May 7, 2024
d537567
adding test_db_sql
antgonza May 7, 2024
1160cf0
missing `
antgonza May 7, 2024
c4f0378
echo $QIITA_CONFIG_FP
antgonza May 7, 2024
a6b4f47
-p 32768
antgonza May 7, 2024
d5db8ad
-l localhost
antgonza May 7, 2024
8a78014
pgport
antgonza May 7, 2024
14ce20f
testing 1
antgonza May 7, 2024
f9cdef5
testing 2
antgonza May 7, 2024
c817edb
localhost
antgonza May 7, 2024
bb9098c
testing 3
antgonza May 7, 2024
2429b15
-h localhost
antgonza May 7, 2024
31ae3bd
-W
antgonza May 7, 2024
df2e14a
PGPASSWORD
antgonza May 7, 2024
822ba80
clean-upls
antgonza May 7, 2024
197c438
doc
antgonza May 7, 2024
26de82c
flake8
antgonza May 7, 2024
f56dc84
mods after chatting with @charles-cowart
antgonza May 7, 2024
813bbee
exit 1
antgonza May 7, 2024
f4462db
"$row_counts"
antgonza May 7, 2024
c5817b0
#
antgonza May 7, 2024
17076e7
`echo $row_counts`
antgonza May 7, 2024
3ef2cdd
full tests
antgonza May 7, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 28 additions & 1 deletion .github/workflows/qiita-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,34 @@ jobs:
QIITA_PID=`cat /tmp/supervisord.pid`
kill $QIITA_PID
sleep 10
if [[ "$COVER_PACKAGE" != *"qiita_db"* ]]; then test_data_studies/commands.sh; all-qiita-cron-job; fi
# due to qiita_db tests being more complex and taking longer than
# the other tests we will only add some extra tests to the run that is
# not testing qiita_db
if [[ "$COVER_PACKAGE" != *"qiita_db"* ]]; then
# 1. testing that we can add some "dummy" studies to the db via
# CLI
test_data_studies/commands.sh;
# 2. making sure that all qiita cron jobs complete as expected
all-qiita-cron-job;
# 3. making sure than a production system has the expected rows
# in all our tables; steps: a. drop test db, b. change $QIITA_CONFIG_FP
# c. create new production system, c. count rows in the db.
qiita-env drop;
cp $QIITA_CONFIG_FP ${QIITA_CONFIG_FP}.bk
sed 's/TEST_ENVIRONMENT = TRUE/TEST_ENVIRONMENT = FALSE/g' ${QIITA_CONFIG_FP}.bk > $QIITA_CONFIG_FP;
qiita-env make --no-load-ontologies;

export PGPASSWORD=postgres
pgport=${{ job.services.postgres.ports[5432] }}
row_counts=`psql -h localhost -U postgres -d qiita_test -p $pgport -c "SELECT SUM(c.reltuples) FROM pg_class c JOIN pg_namespace n on n.oid = c.relnamespace WHERE n.nspname = 'qiita' AND c.relkind = 'r' AND n.nspname NOT IN ('information_schema', 'pg_catalog');"`
if [[ `echo $row_counts` != *" 0 "* ]]; then
echo "***********";
echo "The number of rows in a production system is not what's expected:";
echo $row_counts;
echo "***********";
exit 1
fi
fi

- name: Submit coveralls
uses: AndreMiras/coveralls-python-action@develop
Expand Down
11 changes: 11 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,17 @@ After the initial production release of Qiita, changes to the database schema wi
2. We keep fully patched versions of the DBS and HTML files in the repository
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`)

### Patch 91.sql

In May 2024 we decided to:
* Merge all patches into the main database schema, this means that there are no patches younger than 92.sql.
* Added a new folder `patches/test_db_sql/` where we can store sql files that will only be applied for the test environment.
* Added a test to the GitHub actions to test that the production database has an expected number of rows.

Note that these changes mean:
1. 92.sql is the current first sql file to patch the database.
2. If you need to make changes (like INSERTS) _only_ to the tests database you need to add a patch to `patches/test_db_sql/`.

### Developer Workflow

1. Load the fully patched DBS file (e.g., `qiita-db.dbs`) in [DBSchema](http://www.dbschema.com/)
Expand Down
11 changes: 10 additions & 1 deletion qiita_db/environment_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -381,6 +381,7 @@ def patch(patches_dir=PATCHES_DIR, verbose=False, test=False):
current_patch = qdb.sql_connection.TRN.execute_fetchlast()
current_sql_patch_fp = join(patches_dir, current_patch)
corresponding_py_patch = partial(join, patches_dir, 'python_patches')
corresponding_test_sql = partial(join, patches_dir, 'test_db_sql')

sql_glob = join(patches_dir, '*.sql')
sql_patch_files = natsorted(glob(sql_glob))
Expand All @@ -402,15 +403,23 @@ def patch(patches_dir=PATCHES_DIR, verbose=False, test=False):

patch_prefix = splitext(basename(sql_patch_fp))[0]
py_patch_fp = corresponding_py_patch(f'{patch_prefix}.py')
test_sql_fp = corresponding_test_sql(f'{patch_prefix}.sql')

with qdb.sql_connection.TRN:
with open(sql_patch_fp, newline=None) as patch_file:
if verbose:
print('\tApplying patch %s...' % sql_patch_filename)

qdb.sql_connection.TRN.add(patch_file.read())
qdb.sql_connection.TRN.add(
patch_update_sql, [sql_patch_filename])

if test and exists(test_sql_fp):
if verbose:
print('\t\tApplying test SQL %s...'
% basename(test_sql_fp))
with open(test_sql_fp) as test_sql:
qdb.sql_connection.TRN.add(test_sql.read())

qdb.sql_connection.TRN.execute()

if exists(py_patch_fp):
Expand Down
4 changes: 4 additions & 0 deletions qiita_db/support_files/patches/test_db_sql/92.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
-- .. date ..
-- tmp file for @Gossty

SELECT 1;
Loading