Skip to content

Commit

Permalink
feat(anonymisation): add activity_anonymized, activity_version_anonym…
Browse files Browse the repository at this point in the history
…ized table and query
  • Loading branch information
gaspard-lonchampt committed Nov 13, 2024
1 parent bb3c42d commit edeffdb
Show file tree
Hide file tree
Showing 6 changed files with 393 additions and 47 deletions.
13 changes: 9 additions & 4 deletions app/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -357,14 +357,19 @@ def sync_brevo_command(pipeline_names, verbose):
app.logger.info("Process sync companies with Brevo done")


@app.cli.command("migrate_anonymize_mission", with_appcontext=True)
@app.cli.command("migrate_anonymize_data", with_appcontext=True)
@click.argument("time_interval")
def migrate_anonymize_mission(time_interval):
@click.option(
"--verbose",
is_flag=True,
help="Enable verbose mode for more detailed output",
)
def migrate_anonymize_mission(time_interval, verbose):
"""
Migrate data to anonymized tables.
You can specify time interval as arguments.
"""
from app.services.anonymize_tables import migrate_anonymize_mission
from app.services.anonymize_tables import migrate_anonymized_data

if not time_interval:
print(
Expand All @@ -374,6 +379,6 @@ def migrate_anonymize_mission(time_interval):

app.logger.info("Process with data migration and anonymization began")

migrate_anonymize_mission(time_interval)
migrate_anonymized_data(time_interval, verbose=verbose)

app.logger.info("Process with data migration and anonymization done")
2 changes: 2 additions & 0 deletions app/models/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,5 @@
from .user_survey_actions import UserSurveyActions
from .user_agreement import UserAgreement
from .anonymized.mission import MissionAnonymized
from .anonymized.activity import ActivityAnonymized
from .anonymized.activity_version import ActivityVersionAnonymized
25 changes: 25 additions & 0 deletions app/models/anonymized/activity.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
from app import db
from app.models.activity import Activity


class ActivityAnonymized(Activity):
backref_base_name = "activity_anonymized"
__mapper_args__ = {"concrete": True}

id = db.Column(db.Integer, primary_key=True)
type = db.Column(db.String(8), nullable=True)
user_id = db.Column(db.Integer, nullable=True)
submitter_id = db.Column(db.Integer, nullable=True)
mission_id = db.Column(db.Integer, nullable=True)
dismiss_author_id = db.Column(db.Integer, nullable=True)
dismissed_at = db.Column(db.DateTime, nullable=True)
creation_time = db.Column(db.DateTime, nullable=True)
reception_time = db.Column(db.DateTime, nullable=True)
start_time = db.Column(db.DateTime, nullable=True)
end_time = db.Column(db.DateTime, nullable=True)
last_update_time = db.Column(db.DateTime, nullable=True)
last_submitter_id = db.Column(db.Integer, nullable=True)
dismiss_context = db.Column(db.JSON, nullable=True)

def __repr__(self):
return f"<ActivityAnonymized(id={self.id}, type={self.type}, creation_time={self.creation_time})>"
20 changes: 20 additions & 0 deletions app/models/anonymized/activity_version.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
from app import db
from app.models.activity_version import ActivityVersion


class ActivityVersionAnonymized(ActivityVersion):
backref_base_name = "activity_version_anonymized"
__mapper_args__ = {"concrete": True}

id = db.Column(db.Integer, primary_key=True)
activity_id = db.Column(db.Integer, nullable=True)
version_number = db.Column(db.Integer, nullable=True)
submitter_id = db.Column(db.Integer, nullable=True)
creation_time = db.Column(db.DateTime, nullable=True)
reception_time = db.Column(db.DateTime, nullable=True)
start_time = db.Column(db.DateTime, nullable=True)
end_time = db.Column(db.DateTime, nullable=True)
context = db.Column(db.JSON, nullable=True)

def __repr__(self):
return f"<ActivityVersionAnonymized(id={self.id}, activity_id={self.activity_id}, version_number={self.version_number})>"
Loading

0 comments on commit edeffdb

Please sign in to comment.