From c54de5c62729212e9398ea081b42e455169082c7 Mon Sep 17 00:00:00 2001 From: Jon Date: Sun, 6 Jul 2025 20:23:48 +0930 Subject: [PATCH] feat(access): History + Notes model migrations for Company Model ref: #855 #801 --- ...yaudithistory_companycenturionmodelnote.py | 81 +++++++++++++++++++ app/access/viewsets/__init__.py | 0 app/core/models/meta.py | 4 + app/fixtures/fresh_db.sql | 10 ++- 4 files changed, 91 insertions(+), 4 deletions(-) create mode 100644 app/access/migrations/0019_companyaudithistory_companycenturionmodelnote.py create mode 100644 app/access/viewsets/__init__.py diff --git a/app/access/migrations/0019_companyaudithistory_companycenturionmodelnote.py b/app/access/migrations/0019_companyaudithistory_companycenturionmodelnote.py new file mode 100644 index 00000000..b6152b4d --- /dev/null +++ b/app/access/migrations/0019_companyaudithistory_companycenturionmodelnote.py @@ -0,0 +1,81 @@ +# Generated by Django 5.1.10 on 2025-07-06 10:38 + +import django.db.models.deletion +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ("access", "0018_remove_entity_is_global_alter_entity_id_and_more"), + ("core", "0033_alter_ticketcommentcategory_parent_and_more"), + ] + + operations = [ + migrations.CreateModel( + name="CompanyAuditHistory", + fields=[ + ( + "centurionaudit_ptr", + models.OneToOneField( + auto_created=True, + on_delete=django.db.models.deletion.CASCADE, + parent_link=True, + primary_key=True, + serialize=False, + to="core.centurionaudit", + ), + ), + ( + "model", + models.ForeignKey( + help_text="Model this history belongs to", + on_delete=django.db.models.deletion.CASCADE, + related_name="+", + to="access.company", + verbose_name="Model", + ), + ), + ], + options={ + "verbose_name": "Company History", + "verbose_name_plural": "Company Histories", + "db_table": "access_company_audithistory", + "managed": True, + }, + bases=("core.centurionaudit",), + ), + migrations.CreateModel( + name="CompanyCenturionModelNote", + fields=[ + ( + "centurionmodelnote_ptr", + models.OneToOneField( + auto_created=True, + on_delete=django.db.models.deletion.CASCADE, + parent_link=True, + primary_key=True, + serialize=False, + to="core.centurionmodelnote", + ), + ), + ( + "model", + models.ForeignKey( + help_text="Model this note belongs to", + on_delete=django.db.models.deletion.CASCADE, + related_name="+", + to="access.company", + verbose_name="Model", + ), + ), + ], + options={ + "verbose_name": "Company Note", + "verbose_name_plural": "Company Notes", + "db_table": "access_company_centurionmodelnote", + "managed": True, + }, + bases=("core.centurionmodelnote",), + ), + ] diff --git a/app/access/viewsets/__init__.py b/app/access/viewsets/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/app/core/models/meta.py b/app/core/models/meta.py index 3d84696e..3c261fb7 100644 --- a/app/core/models/meta.py +++ b/app/core/models/meta.py @@ -5,6 +5,10 @@ from django.apps import apps from django.db import models from django.utils.module_loading import import_string +# Note: Only included so that it can be picked up. +# in future when model referenced, this include statement may be repoved. +from access.models.company_base import Company # pylint: disable=W0611:unused-import + module_path = f'centurion.models.meta' diff --git a/app/fixtures/fresh_db.sql b/app/fixtures/fresh_db.sql index 131829b2..488a9a6c 100644 --- a/app/fixtures/fresh_db.sql +++ b/app/fixtures/fresh_db.sql @@ -98,8 +98,8 @@ CREATE TABLE IF NOT EXISTS "devops_git_group_history" ("modelhistory_ptr_id" int CREATE TABLE IF NOT EXISTS "devops_github_repository_notes" ("modelnotes_ptr_id" integer NOT NULL PRIMARY KEY REFERENCES "core_model_notes" ("id") DEFERRABLE INITIALLY DEFERRED, "model_id" integer NOT NULL REFERENCES "devops_githubrepository" ("gitrepository_ptr_id") DEFERRABLE INITIALLY DEFERRED); CREATE TABLE IF NOT EXISTS "devops_gitlab_repository_notes" ("modelnotes_ptr_id" integer NOT NULL PRIMARY KEY REFERENCES "core_model_notes" ("id") DEFERRABLE INITIALLY DEFERRED, "model_id" integer NOT NULL REFERENCES "devops_gitlabrepository" ("gitrepository_ptr_id") DEFERRABLE INITIALLY DEFERRED); CREATE TABLE IF NOT EXISTS "devops_git_group_notes" ("modelnotes_ptr_id" integer NOT NULL PRIMARY KEY REFERENCES "core_model_notes" ("id") DEFERRABLE INITIALLY DEFERRED, "model_id" integer NOT NULL REFERENCES "devops_gitgroup" ("id") DEFERRABLE INITIALLY DEFERRED); -CREATE TABLE IF NOT EXISTS "access_organization_history" ("modelhistory_ptr_id" integer NOT NULL PRIMARY KEY REFERENCES "core_model_history" ("id") DEFERRABLE INITIALLY DEFERRED, "model_id" integer NOT NULL REFERENCES "access_tenant" ("id") DEFERRABLE INITIALLY DEFERRED); CREATE TABLE IF NOT EXISTS "access_organization_notes" ("modelnotes_ptr_id" integer NOT NULL PRIMARY KEY REFERENCES "core_model_notes" ("id") DEFERRABLE INITIALLY DEFERRED, "model_id" integer NOT NULL REFERENCES "access_tenant" ("id") DEFERRABLE INITIALLY DEFERRED); +CREATE TABLE IF NOT EXISTS "access_organization_history" ("modelhistory_ptr_id" integer NOT NULL PRIMARY KEY REFERENCES "core_model_history" ("id") DEFERRABLE INITIALLY DEFERRED, "model_id" integer NOT NULL REFERENCES "access_tenant" ("id") DEFERRABLE INITIALLY DEFERRED); CREATE TABLE IF NOT EXISTS "access_company" ("entity_ptr_id" integer NOT NULL PRIMARY KEY REFERENCES "access_entity" ("id") DEFERRABLE INITIALLY DEFERRED, "name" varchar(80) NOT NULL); CREATE TABLE IF NOT EXISTS "access_person" ("entity_ptr_id" integer NOT NULL PRIMARY KEY REFERENCES "access_entity" ("id") DEFERRABLE INITIALLY DEFERRED, "f_name" varchar(64) NOT NULL, "l_name" varchar(64) NOT NULL, "dob" date NULL, "m_name" varchar(100) NULL); CREATE TABLE IF NOT EXISTS "core_ticketcommentaction" ("ticketcommentbase_ptr_id" integer NOT NULL PRIMARY KEY REFERENCES "core_ticketcommentbase" ("id") DEFERRABLE INITIALLY DEFERRED); @@ -137,6 +137,8 @@ CREATE TABLE IF NOT EXISTS "access_entity_audithistory" ("centurionaudit_ptr_id" CREATE TABLE IF NOT EXISTS "access_entity_centurionmodelnote" ("centurionmodelnote_ptr_id" integer NOT NULL PRIMARY KEY REFERENCES "core_centurionmodelnote" ("id") DEFERRABLE INITIALLY DEFERRED, "model_id" integer NOT NULL REFERENCES "access_entity" ("id") DEFERRABLE INITIALLY DEFERRED); CREATE TABLE IF NOT EXISTS "access_person_audithistory" ("centurionaudit_ptr_id" integer NOT NULL PRIMARY KEY REFERENCES "core_audithistory" ("id") DEFERRABLE INITIALLY DEFERRED, "model_id" integer NOT NULL REFERENCES "access_person" ("entity_ptr_id") DEFERRABLE INITIALLY DEFERRED); CREATE TABLE IF NOT EXISTS "access_person_centurionmodelnote" ("centurionmodelnote_ptr_id" integer NOT NULL PRIMARY KEY REFERENCES "core_centurionmodelnote" ("id") DEFERRABLE INITIALLY DEFERRED, "model_id" integer NOT NULL REFERENCES "access_person" ("entity_ptr_id") DEFERRABLE INITIALLY DEFERRED); +CREATE TABLE IF NOT EXISTS "access_company_audithistory" ("centurionaudit_ptr_id" integer NOT NULL PRIMARY KEY REFERENCES "core_audithistory" ("id") DEFERRABLE INITIALLY DEFERRED, "model_id" integer NOT NULL REFERENCES "access_company" ("entity_ptr_id") DEFERRABLE INITIALLY DEFERRED); +CREATE TABLE IF NOT EXISTS "access_company_centurionmodelnote" ("centurionmodelnote_ptr_id" integer NOT NULL PRIMARY KEY REFERENCES "core_centurionmodelnote" ("id") DEFERRABLE INITIALLY DEFERRED, "model_id" integer NOT NULL REFERENCES "access_company" ("entity_ptr_id") DEFERRABLE INITIALLY DEFERRED); CREATE TABLE IF NOT EXISTS "accounting_assetbase" ("model_notes" text NULL, "id" integer NOT NULL PRIMARY KEY AUTOINCREMENT, "asset_number" varchar(30) NULL UNIQUE, "serial_number" varchar(30) NULL UNIQUE, "asset_type" varchar(30) NOT NULL, "created" datetime NOT NULL, "modified" datetime NOT NULL, "organization_id" integer NOT NULL REFERENCES "access_tenant" ("id") DEFERRABLE INITIALLY DEFERRED); CREATE TABLE IF NOT EXISTS "accounting_assetbase_history" ("modelhistory_ptr_id" integer NOT NULL PRIMARY KEY REFERENCES "core_model_history" ("id") DEFERRABLE INITIALLY DEFERRED, "model_id" integer NOT NULL REFERENCES "accounting_assetbase" ("id") DEFERRABLE INITIALLY DEFERRED); CREATE TABLE IF NOT EXISTS "accounting_assetbase_notes" ("modelnotes_ptr_id" integer NOT NULL PRIMARY KEY REFERENCES "core_model_notes" ("id") DEFERRABLE INITIALLY DEFERRED, "model_id" integer NOT NULL REFERENCES "accounting_assetbase" ("id") DEFERRABLE INITIALLY DEFERRED); @@ -235,9 +237,9 @@ CREATE TABLE IF NOT EXISTS "social_auth_nonce" ("id" integer NOT NULL PRIMARY KE CREATE TABLE IF NOT EXISTS "social_auth_usersocialauth" ("id" integer NOT NULL PRIMARY KEY AUTOINCREMENT, "provider" varchar(32) NOT NULL, "uid" varchar(255) NOT NULL, "user_id" integer NOT NULL REFERENCES "auth_user" ("id") DEFERRABLE INITIALLY DEFERRED, "created" datetime NOT NULL, "modified" datetime NOT NULL, "extra_data" text NOT NULL CHECK ((JSON_VALID("extra_data") OR "extra_data" IS NULL))); CREATE TABLE IF NOT EXISTS "social_auth_partial" ("id" integer NOT NULL PRIMARY KEY AUTOINCREMENT, "token" varchar(32) NOT NULL, "next_step" smallint unsigned NOT NULL CHECK ("next_step" >= 0), "backend" varchar(32) NOT NULL, "timestamp" datetime NOT NULL, "data" text NOT NULL CHECK ((JSON_VALID("data") OR "data" IS NULL))); DELETE FROM sqlite_sequence; -INSERT INTO sqlite_sequence VALUES('django_migrations',221); -INSERT INTO sqlite_sequence VALUES('django_content_type',214); -INSERT INTO sqlite_sequence VALUES('auth_permission',901); +INSERT INTO sqlite_sequence VALUES('django_migrations',222); +INSERT INTO sqlite_sequence VALUES('django_content_type',216); +INSERT INTO sqlite_sequence VALUES('auth_permission',909); INSERT INTO sqlite_sequence VALUES('auth_group',0); INSERT INTO sqlite_sequence VALUES('auth_user',0); INSERT INTO sqlite_sequence VALUES('core_notes',0);