summaryrefslogtreecommitdiff
path: root/auditlog/migrations
diff options
context:
space:
mode:
authorstephanchrst <stephanchrst@gmail.com>2023-02-06 15:29:55 +0700
committerstephanchrst <stephanchrst@gmail.com>2023-02-06 15:29:55 +0700
commit7cfed1e19f2e340d966ed2068176d21a0e8e9834 (patch)
treeec9077cb4f89d23378ef09f9da0adb7135548081 /auditlog/migrations
parent4b3b2d8b1a9a7a72fbe3d623e93dea3802ef0e56 (diff)
add audit log
Diffstat (limited to 'auditlog/migrations')
-rw-r--r--auditlog/migrations/14.0.1.1.0/pre-migration.py73
1 files changed, 73 insertions, 0 deletions
diff --git a/auditlog/migrations/14.0.1.1.0/pre-migration.py b/auditlog/migrations/14.0.1.1.0/pre-migration.py
new file mode 100644
index 0000000..53a120e
--- /dev/null
+++ b/auditlog/migrations/14.0.1.1.0/pre-migration.py
@@ -0,0 +1,73 @@
+# © 2018 Pieter Paulussen <pieter_paulussen@me.com>
+# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
+import logging
+
+
+def migrate(cr, version):
+ if not version:
+ return
+ logger = logging.getLogger(__name__)
+ logger.info(
+ "Creating columns: auditlog_log (model_name, model_model) "
+ "and auditlog_log_line (field_name, field_description)."
+ )
+ cr.execute(
+ """
+ ALTER TABLE auditlog_log
+ ADD COLUMN IF NOT EXISTS model_name VARCHAR,
+ ADD COLUMN IF NOT EXISTS model_model VARCHAR;
+ ALTER TABLE auditlog_log_line
+ ADD COLUMN IF NOT EXISTS field_name VARCHAR,
+ ADD COLUMN IF NOT EXISTS field_description VARCHAR;
+ ALTER TABLE auditlog_rule
+ ADD COLUMN IF NOT EXISTS model_name VARCHAR,
+ ADD COLUMN IF NOT EXISTS model_model VARCHAR;
+ """
+ )
+ logger.info(
+ "Creating indexes on auditlog_log column 'model_id' and "
+ "auditlog_log_line column 'field_id'."
+ )
+ cr.execute(
+ """
+ CREATE INDEX IF NOT EXISTS
+ auditlog_log_model_id_index ON auditlog_log (model_id);
+ CREATE INDEX IF NOT EXISTS
+ auditlog_log_line_field_id_index ON auditlog_log_line (field_id);
+ """
+ )
+ logger.info(
+ "Preemptive fill auditlog_log columns: 'model_name' and " "'model_model'."
+ )
+ cr.execute(
+ """
+ UPDATE auditlog_log al
+ SET model_name = im.name, model_model = im.model
+ FROM ir_model im
+ WHERE im.id = al.model_id AND model_name IS NULL
+ """
+ )
+ logger.info(
+ "Preemtive fill of auditlog_log_line columns: 'field_name' and"
+ " 'field_description'."
+ )
+ cr.execute(
+ """
+ UPDATE auditlog_log_line al
+ SET field_name = imf.name, field_description = imf.field_description
+ FROM ir_model_fields imf
+ WHERE imf.id = al.field_id AND field_name IS NULL
+ """
+ )
+ logger.info(
+ "Preemptive fill auditlog_rule columns: 'model_name' and " "'model_model'."
+ )
+ cr.execute(
+ """
+ UPDATE auditlog_rule al
+ SET model_name = im.name, model_model = im.model
+ FROM ir_model im
+ WHERE im.id = al.model_id AND model_name IS NULL
+ """
+ )
+ logger.info("Successfully updated auditlog tables")