Renaming column type to category for external audit event destinations
What does this MR do and why?
Tables audit_events_group_external_streaming_destinations
and audit_events_instance_external_streaming_destinations
were recently introduced in MRs !141739 (merged) and !143247 (merged).
I noticed a problem with these tables, I had added a field named type
in them for storing the type of destination for which the config is stored in them. Later I realised that type
is a reserved keyword for column name and can only be used for inheritance only. This is creating problems now, while adding other functionalities, so need to rename the column name to category
.
Error while creating the destinations object was:
ActiveRecord::SubclassNotFound: The single-table inheritance mechanism failed to locate the subclass: 'http'. This error is raised because the column 'type' is reserved for storing the class in case of inheritance. Please rename this column if you didn't intend it to be used for storing the inheritance class or overwrite AuditEvents::Group::ExternalStreamingDestination.inheritance_column to use another column for that information.
These 2 tables are recently introduced and are not in use at all, and hence 0 rows, so for that reason, I am directly using `rename_column` here in migration, rather than going through the process mentioned in https://docs.gitlab.com/ee/development/database/avoiding_downtime_in_migrations.html#renaming-columns.
Migrations
Group
bundle exec rake db:migrate:up:main VERSION=20240216133415
main: == [advisory_lock_connection] object_id: 116720, pg_backend_pid: 36453
main: == 20240216133415 RenameTypeColumnOfGroupExternalStreamingDestination: migrating
main: -- rename_column(:audit_events_group_external_streaming_destinations, :type, :category)
main: -> 0.0238s
main: == 20240216133415 RenameTypeColumnOfGroupExternalStreamingDestination: migrated (0.0277s)main: == [advisory_lock_connection] object_id: 116720, pg_backend_pid: 36453
#############################################################
Down
#############################################################
bundle exec rake db:migrate:down:main VERSION=20240216133415
main: == [advisory_lock_connection] object_id: 116720, pg_backend_pid: 35915
main: == 20240216133415 RenameTypeColumnOfGroupExternalStreamingDestination: reverting
main: -- rename_column(:audit_events_group_external_streaming_destinations, :category, :type)
main: -> 0.0276s
main: == 20240216133415 RenameTypeColumnOfGroupExternalStreamingDestination: reverted (0.0363s)main: == [advisory_lock_connection] object_id: 116720, pg_backend_pid: 35915
Instance
bundle exec rake db:migrate:up:main VERSION=20240216133523
main: == [advisory_lock_connection] object_id: 116700, pg_backend_pid: 35269
main: == 20240216133523 RenameTypeColumnOfInstanceExternalStreamingDestination: migrating
main: -- rename_column(:audit_events_instance_external_streaming_destinations, :type, :category)
main: -> 0.0229s
main: == 20240216133523 RenameTypeColumnOfInstanceExternalStreamingDestination: migrated (0.0320s)main: == [advisory_lock_connection] object_id: 116700, pg_backend_pid: 35269
#############################################################
Down
#############################################################
bundle exec rake db:migrate:down:main VERSION=20240216133523
main: == [advisory_lock_connection] object_id: 117840, pg_backend_pid: 34651
main: == 20240216133523 RenameTypeColumnOfInstanceExternalStreamingDestination: reverting
main: -- rename_column(:audit_events_instance_external_streaming_destinations, :category, :type)
main: -> 0.0242s
main: == 20240216133523 RenameTypeColumnOfInstanceExternalStreamingDestination: reverted (0.0294s)main: == [advisory_lock_connection] object_id: 117840, pg_backend_pid: 34651
MR acceptance checklist
Please evaluate this MR against the MR acceptance checklist. It helps you analyze changes to reduce risks in quality, performance, reliability, security, and maintainability.
Screenshots or screen recordings
Screenshots are required for UI changes, and strongly recommended for all other merge requests.
Before | After |
---|---|
How to set up and validate locally
Numbered steps to set up and validate the change are strongly suggested.
Related to #442199 (closed)