Project

General

Profile

Bug #10740

Audits created during DB migration of ptables to templates

Added by Dominic Cleal almost 5 years ago. Updated almost 2 years ago.

Status:
Closed
Priority:
Normal
Assignee:
Category:
DB migrations
Target version:
Difficulty:
Triaged:
Bugzilla link:
Fixed in Releases:
Found in Releases:

Description

When migrating over #7096, audits are created due to the update of ptable_id on hosts and host groups.

2015-06-09T14:47:28 [sql] [I] Migrating to MigratePtablesToTemplates (20150514114044)
-- migrating partition table Kickstart default
...
2015-06-09T14:47:30 [sql] [D]   Host::Managed Load (0.2ms)  SELECT "hosts".* FROM "hosts" WHERE "hosts"."type" IN ('Host::Managed') AND "hosts"."id" = 168 LIMIT 1
2015-06-09T14:47:30 [sql] [D]    (0.1ms)  SELECT MAX("audits"."version") AS max_id FROM "audits" WHERE "audits"."auditable_id" = 168 AND "audits"."auditable_type" = 'Host'
2015-06-09T14:47:30 [sql] [D]   SQL (0.3ms)  INSERT INTO "audits" ("action", "associated_id", "associated_name", "associated_type", "auditable_id", "auditable_name", "auditable_type", "audited_changes", "comment", "created_at", "remote_address", "request_uuid", "user_id",
 "user_type", "username", "version") VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)  [["action", "update"], ["associated_id", nil], ["associated_name", nil], ["associated_type", nil], ["auditable_id", 168], ["auditable_name", "test.example.com"], ["auditable_type
", "Host"], ["audited_changes", "---\nptable_id:\n- 12\n- 86\n"], ["comment", nil], ["created_at", Tue, 09 Jun 2015 13:47:30 UTC +00:00], ["remote_address", nil], ["request_uuid", nil], ["user_id", nil], ["user_type", nil], ["username", nil], ["version", 7]]

Related issues

Related to Foreman - Feature #7096: Partition Tables should just be a kind of Provisioning TemplatesClosed2014-08-14
Related to Foreman - Bug #14965: Migration error in foreman_bootdisk upgrading from 6.1 to 6.2Closed2016-05-09

Associated revisions

Revision 68bf0c89 (diff)
Added by Marek Hulán almost 5 years ago

Fixes #10740 - ignore auditing of all models in migrations

History

#1 Updated by Dominic Cleal almost 5 years ago

  • Related to Feature #7096: Partition Tables should just be a kind of Provisioning Templates added

#2 Updated by Dominic Cleal almost 5 years ago

I wonder if we ought to use this more:

self.auditing_enabled = !Foreman.in_rake?('db:migrate')

Used today in a few models such as provisioning template.

#3 Updated by The Foreman Bot almost 5 years ago

  • Status changed from Assigned to Ready For Testing
  • Pull request https://github.com/theforeman/foreman/pull/2447 added
  • Pull request deleted ()

#4 Updated by Marek Hulán almost 5 years ago

I didn't find an easy way how to hook into audited so it would set auditing_enabled = !Foreman.in_rake?('db:migrate') for all audited models. I could go through all such models and add it manually if you want. For new audited models I'm afraid we'll forget to add to though. Maybe some global auditing switch in audited gem would help.

#5 Updated by Ohad Levy almost 5 years ago

Marek Hulán wrote:

I didn't find an easy way how to hook into audited so it would set auditing_enabled = !Foreman.in_rake?('db:migrate') for all audited models. I could go through all such models and add it manually if you want. For new audited models I'm afraid we'll forget to add to though. Maybe some global auditing switch in audited gem would help.

cant you change the base class? or even in the audit initializer, as you init the whole app as rake?

#6 Updated by Marek Hulán almost 5 years ago

This accessor is defined by calling audited so it's not present in ActiveRecord::Base I could monkey patch it but it seems a bit weird that models that are not audited would have this method defined. Hopefully it won't do any harm later, so far I like it the most. I'm not sure what exactly do you mean by audit initializer, creating a new initializer that would change the auditing flag? If we define this method in ActiveRecord::Base then I think it's sufficient to check there.

EDIT: oh I didn't realize that audited call will override the accessor value so we can't simply set it in ActiveRecord::Base

#7 Updated by Marek Hulán almost 5 years ago

  • Status changed from Ready For Testing to Closed
  • % Done changed from 0 to 100

#8 Updated by Martin Bacovsky about 4 years ago

  • Related to Bug #14965: Migration error in foreman_bootdisk upgrading from 6.1 to 6.2 added

Also available in: Atom PDF