From 486ce2dc390fd4054b0bbaee91df9953e211903a Mon Sep 17 00:00:00 2001 From: Taha Yassine Kraiem Date: Tue, 15 Nov 2022 16:38:20 +0100 Subject: [PATCH] feat(chalice): add session_id to recordings --- ee/api/chalicelib/core/assist_records.py | 7 ++++--- ee/api/schemas_ee.py | 4 ++++ ee/scripts/schema/db/init_dbs/postgresql/1.9.5/1.9.5.sql | 1 + ee/scripts/schema/db/init_dbs/postgresql/init_schema.sql | 1 + 4 files changed, 10 insertions(+), 3 deletions(-) diff --git a/ee/api/chalicelib/core/assist_records.py b/ee/api/chalicelib/core/assist_records.py index 4c39bbe83..c5a7dd0dd 100644 --- a/ee/api/chalicelib/core/assist_records.py +++ b/ee/api/chalicelib/core/assist_records.py @@ -16,11 +16,12 @@ def presign_records(project_id, data: schemas_ee.AssistRecordUploadPayloadSchema key=s3.generate_file_key(project_id=project_id, key=key))) params[f"name_{i}"] = r.name params[f"duration_{i}"] = r.duration + params[f"session_id_{i}"] = r.session_id params[f"key_{i}"] = key with pg_client.PostgresClient() as cur: - values = [f"(%(project_id)s, %(user_id)s, %(name_{i})s, %(key_{i})s, %(duration_{i})s)" for i in - range(len(data.records))] - query = cur.mogrify(f"""INSERT INTO assist_records(project_id, user_id, name, file_key, duration) + values = [f"(%(project_id)s, %(user_id)s, %(name_{i})s, %(key_{i})s, %(duration_{i})s, %(session_id_{i})s)" + for i in range(len(data.records))] + query = cur.mogrify(f"""INSERT INTO assist_records(project_id, user_id, name, file_key, duration, session_id) VALUES {",".join(values)}""", params) cur.execute(query) return results diff --git a/ee/api/schemas_ee.py b/ee/api/schemas_ee.py index efd88f580..620074e61 100644 --- a/ee/api/schemas_ee.py +++ b/ee/api/schemas_ee.py @@ -86,6 +86,10 @@ class SessionModel(BaseModel): class AssistRecord(BaseModel): name: str = Field(...) duration: int = Field(...) + session_id: int = Field(...) + + class Config: + alias_generator = schemas.attribute_to_camel_case class AssistRecordUploadPayloadSchema(BaseModel): diff --git a/ee/scripts/schema/db/init_dbs/postgresql/1.9.5/1.9.5.sql b/ee/scripts/schema/db/init_dbs/postgresql/1.9.5/1.9.5.sql index 245b2f85d..fde3e381f 100644 --- a/ee/scripts/schema/db/init_dbs/postgresql/1.9.5/1.9.5.sql +++ b/ee/scripts/schema/db/init_dbs/postgresql/1.9.5/1.9.5.sql @@ -10,6 +10,7 @@ CREATE TABLE IF NOT EXISTS assist_records record_id integer generated BY DEFAULT AS IDENTITY PRIMARY KEY, project_id integer NOT NULL REFERENCES projects (project_id) ON DELETE CASCADE, user_id integer NOT NULL REFERENCES users (user_id) ON DELETE SET NULL, + session_id integer NOT NULL REFERENCES sessions (session_id) ON DELETE SET NULL, created_at timestamp without time zone NOT NULL default (now() at time zone 'utc'), deleted_at timestamp without time zone NULL DEFAULT NULL, name text NOT NULL, diff --git a/ee/scripts/schema/db/init_dbs/postgresql/init_schema.sql b/ee/scripts/schema/db/init_dbs/postgresql/init_schema.sql index 16353f4fd..0a1b238b6 100644 --- a/ee/scripts/schema/db/init_dbs/postgresql/init_schema.sql +++ b/ee/scripts/schema/db/init_dbs/postgresql/init_schema.sql @@ -1251,6 +1251,7 @@ $$ record_id integer generated BY DEFAULT AS IDENTITY PRIMARY KEY, project_id integer NOT NULL REFERENCES projects (project_id) ON DELETE CASCADE, user_id integer NOT NULL REFERENCES users (user_id) ON DELETE SET NULL, + session_id integer NOT NULL REFERENCES sessions (session_id) ON DELETE SET NULL, created_at timestamp without time zone NOT NULL default (now() at time zone 'utc'), deleted_at timestamp without time zone NULL DEFAULT NULL, name text NOT NULL,