Skip to content

Commit

Permalink
Disable Postgres logging during tests for new table (#294)
Browse files Browse the repository at this point in the history
* Don't try and log the auditlog table when generating fixtures

This is breaking things, as `member` has a foreign key reference to this table and you can't mix logged and unlogged tables.

* Make disabling database logging optional
  • Loading branch information
thebeanogamer authored Oct 7, 2022
1 parent 497ee22 commit 2007ff6
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 5 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/integrate.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ jobs:
run: sleep 10

- name: Generate Test Fixtures
run: docker exec -w /app --tty $(docker-compose ps -q backend) make fake-data ARGS="--teams 10 --users 2 --categories 10 --challenges 100 --solves 1000"
run: docker exec -w /app --tty $(docker-compose ps -q backend) make fake-data ARGS="--teams 10 --users 2 --categories 10 --challenges 100 --solves 1000 --zoom"

- name: Confirm Upstream is Healthy
run: curl -v --fail localhost:8000/api/v2/stats/stats/
Expand Down
3 changes: 2 additions & 1 deletion scripts/fake/__init__.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
"""A command-line tool for generating and inserting many rows of fake data into the database.
Usage:
fake generate [--teams=<teams>] [--users=<users>] [--categories=<categories>] [--challenges=<challenges>] [--solves=<solves>] [--force]
fake generate [--teams=<teams>] [--users=<users>] [--categories=<categories>] [--challenges=<challenges>] [--solves=<solves>] [--force] [--zoom]
fake -h | --help
Options:
--help -h Show this screen.
--force Run even when the database is populated.
--zoom Disable Postgres logging so the script runs faster.
--users=<users> The number of users to generate per team. [default: 2]
--categories=<categories> The number of categories to generate. [default: 5]
Expand Down
7 changes: 4 additions & 3 deletions scripts/fake/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,10 @@
db_indexes[table] = indexes
db_constraints[table] = constraints

for table in TABLE_NAMES:
cursor.execute(f"ALTER TABLE {table} SET UNLOGGED")
db.connection.commit()
if arguments.get("zoom"):
for table in TABLE_NAMES:
cursor.execute(f"ALTER TABLE {table} SET UNLOGGED")
db.connection.commit()

with TimedLog("Inserting data... ", ending="\n"):
fake = Faker()
Expand Down
1 change: 1 addition & 0 deletions scripts/fake/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ def dsn(cls) -> str:


TABLE_NAMES = [
"admin_auditlogentry",
"member_member_groups",
"authentication_token",
"member_member_user_permissions",
Expand Down

0 comments on commit 2007ff6

Please sign in to comment.