Add updated_at columns and Postgres triggers#379
Open
silentgeckoaudit3801 wants to merge 5 commits into
Open
Conversation
| def test_core_audit_models_have_updated_at_columns(): | ||
| for class_name in ("User", "Position", "AirDrop"): | ||
| body = _class_body(class_name) | ||
| assert "updated_at = Column" in body |
| for table_name in ("user", "position", "airdrop"): | ||
| assert f'op.add_column(\n table_name,' in MIGRATION | ||
| assert f'for table_name in ("user", "position", "airdrop"):' in MIGRATION | ||
| assert 'op.drop_column(table_name, "updated_at")' in MIGRATION |
|
|
||
|
|
||
| def test_migration_installs_triggers_for_all_updated_at_tables(): | ||
| assert "CREATE OR REPLACE FUNCTION set_updated_at()" in MIGRATION |
|
|
||
| def test_migration_installs_triggers_for_all_updated_at_tables(): | ||
| assert "CREATE OR REPLACE FUNCTION set_updated_at()" in MIGRATION | ||
| assert "NEW.updated_at = NOW();" in MIGRATION |
| "extra_deposits", | ||
| "event_outbox", | ||
| ): | ||
| assert f'"{table_name}"' in MIGRATION |
| "event_outbox", | ||
| ): | ||
| assert f'"{table_name}"' in MIGRATION | ||
| assert "CREATE TRIGGER" in MIGRATION |
| ): | ||
| assert f'"{table_name}"' in MIGRATION | ||
| assert "CREATE TRIGGER" in MIGRATION | ||
| assert "EXECUTE FUNCTION set_updated_at();" in MIGRATION No newline at end of file |
| for class_name in ("User", "Position", "AirDrop"): | ||
| body = _class_body(class_name) | ||
| assert "updated_at = Column" in body | ||
| assert "onupdate=func.now()" in body |
|
|
||
|
|
||
| def test_migration_adds_missing_updated_at_columns(): | ||
| assert 'for table_name in ("user", "position", "airdrop"):' in MIGRATION |
| def test_migration_adds_missing_updated_at_columns(): | ||
| assert 'for table_name in ("user", "position", "airdrop"):' in MIGRATION | ||
| for table_name in ("user", "position", "airdrop"): | ||
| assert f'op.add_column(\n table_name,' in MIGRATION |
| assert 'for table_name in ("user", "position", "airdrop"):' in MIGRATION | ||
| for table_name in ("user", "position", "airdrop"): | ||
| assert f'op.add_column(\n table_name,' in MIGRATION | ||
| assert table_name in MIGRATION |
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #229.
This makes updated_at consistent for the audit-facing models and moves the timestamp update guarantee into Postgres:
ow() defaults
I did not run local pytest/Alembic commands in this workspace because we are intentionally avoiding dependency installation and project toolchain execution.