Skip to content

Commit

Permalink
Merge pull request #31 from betagouv/install-postgressql-audit-0-12-4
Browse files Browse the repository at this point in the history
Install postgressql audit 0 12 4
  • Loading branch information
Ledoux committed Apr 7, 2021
2 parents 9eb230e + 074ba3d commit 807c114
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 11 deletions.
4 changes: 3 additions & 1 deletion api/utils/database.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@


def delete():
logger.info('Delete all the database...')
logger.info('Delete all the tables...')
for table in reversed(db.metadata.sorted_tables):
print('Deleting table {table_name}...'.format(table_name=table))
db.session.execute(table.delete())
Expand All @@ -26,6 +26,8 @@ def delete():

def create_activity_and_transaction_tables():
orm.configure_mappers()
db.session.execute("CREATE EXTENSION btree_gist;")
db.session.commit()
Activity = ApiHandler.get_activity()
Activity.transaction.mapper.class_.__table__.create(db.session.get_bind())
Activity.__table__.create(db.session.get_bind())
Expand Down
2 changes: 1 addition & 1 deletion requirements-test.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ flask-login==0.4.1
flask_script==2.0.6
flask_sqlalchemy==2.4.1
pip-licenses==1.10.0
PostgreSQL-Audit==0.10.0
PostgreSQL-Audit==0.12.4
pytest==4.0.0
pytest-cov==2.6.1
pytest-flask==0.14.0
Expand Down
14 changes: 13 additions & 1 deletion sqlaah
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,6 @@ elif [[ "$CMD" == "celery" ]]; then
check start apischeduler
check start apiweb
check start api${QUEUE}worker
check start apislowworker
docker exec ${APP_NAME}-api${QUEUE}worker bash -c "cd /opt/api && celery $SUB_COMMANDS"
exit_with_success

Expand All @@ -95,6 +94,16 @@ elif [[ "$CMD" == "database" ]]; then
exit_with_success


# Run pip, ex ./$COMMAND_NAME celery upgrade HEAD
elif [[ "$CMD" == "pip" ]]; then
SUB_COMMANDS=$*
check start apidefaultworker
check start apiweb
docker exec ${APP_NAME}-apidefaultworker bash -c "cd /opt/api && pip $SUB_COMMANDS"
docker exec ${APP_NAME}-apiweb bash -c "cd /opt/api && pip $SUB_COMMANDS"
exit_with_success


# Connect to Postgresql database in command line using psql
elif [[ "$CMD" == "psql" ]]; then
check start apipostgresdb
Expand All @@ -118,6 +127,9 @@ elif [[ "$CMD" == "prepublish" ]]; then
exit_with_success





# Publish package to PyPi
elif [[ "$CMD" == "publish" ]]; then
check start apiweb
Expand Down
2 changes: 1 addition & 1 deletion sqlalchemy_api_handler/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from sqlalchemy_api_handler.api_errors import *
from sqlalchemy_api_handler.api_handler import *

__version__ = '0.14.11'
__version__ = '0.15.1'
11 changes: 5 additions & 6 deletions sqlalchemy_api_handler/bases/activate.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,14 +115,13 @@ def activate(*activities,

db = Activate.get_db()
db.session.add_all(grouped_activities)
db.session.execute(f'ALTER TABLE {model.__tablename__} DISABLE TRIGGER audit_trigger_update;')
if model.id.key in merged_datum:
del merged_datum[model.id.key]
entity.modify(merged_datum,
with_add=True,
with_check_not_soft_deleted=with_check_not_soft_deleted)
db.session.flush()
db.session.execute(f'ALTER TABLE {model.__tablename__} ENABLE TRIGGER audit_trigger_update;')
with versioning_manager.disable(db.session):
entity.modify(merged_datum,
with_add=True,
with_check_not_soft_deleted=with_check_not_soft_deleted)
db.session.flush()


@classmethod
Expand Down
2 changes: 1 addition & 1 deletion tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

try:
create()
except Exception:
except Exception as ExpectedExceptionIfDatabaseAlreadyCreatedAtPreviousRun:
pass


Expand Down

0 comments on commit 807c114

Please sign in to comment.