Skip to content

Adding table and model for group namespace filters

Hitesh Raghuvanshi requested to merge 436605-group-namespace-filters into master

What does this MR do and why?

As part of consolidation of external audit event streaming destinations in &12339, we are creating a new table for storing namespace filters for group level audit event streaming destinations.

In this MR:

  1. Table audit_events_streaming_group_namespace_filters for storing namespace filters for destinations is created. Combination of namespace and destination should be unique.
  2. Since there are 2 foreign keys associated with this table, so we are adding them in different migrations as per https://docs.gitlab.com/ee/development/migration_style_guide.html#creating-a-new-table-when-we-have-two-foreign-keys.
  3. We are also adding a limit of 5 namespace filters per destination.

Database

Destination foreign key migration


## up

bundle exec rake db:migrate:up:main VERSION=20240419074624
main: == [advisory_lock_connection] object_id: 121660, pg_backend_pid: 75228
main: == 20240419074624 AddDestinationFkToAuditEventsGroupNamespaceFilters: migrating 
main: -- transaction_open?(nil)
main:    -> 0.0000s
main: -- transaction_open?(nil)
main:    -> 0.0000s
main: -- execute("ALTER TABLE audit_events_streaming_group_namespace_filters ADD CONSTRAINT fk_8ed182d7da FOREIGN KEY (external_streaming_destination_id) REFERENCES audit_events_group_external_streaming_destinations (id) ON DELETE CASCADE NOT VALID;")
main:    -> 0.0027s
main: -- execute("SET statement_timeout TO 0")
main:    -> 0.0001s
main: -- execute("ALTER TABLE audit_events_streaming_group_namespace_filters VALIDATE CONSTRAINT fk_8ed182d7da;")
main:    -> 0.0032s
main: -- execute("RESET statement_timeout")
main:    -> 0.0001s
main: == 20240419074624 AddDestinationFkToAuditEventsGroupNamespaceFilters: migrated (0.0343s) 

main: == [advisory_lock_connection] object_id: 121660, pg_backend_pid: 75228


## down

bundle exec rake db:migrate:down:main VERSION=20240419074624           
main: == [advisory_lock_connection] object_id: 121700, pg_backend_pid: 74709
main: == 20240419074624 AddDestinationFkToAuditEventsGroupNamespaceFilters: reverting 
main: -- transaction_open?(nil)
main:    -> 0.0000s
main: -- remove_foreign_key(:audit_events_streaming_group_namespace_filters, {:column=>:external_streaming_destination_id})
main:    -> 0.0028s
main: == 20240419074624 AddDestinationFkToAuditEventsGroupNamespaceFilters: reverted (0.0451s) 

main: == [advisory_lock_connection] object_id: 121700, pg_backend_pid: 74709

Namespace foreign key migration


## up

 bundle exec rake db:migrate:up:main VERSION=20240419074648
main: == [advisory_lock_connection] object_id: 121680, pg_backend_pid: 76506
main: == 20240419074648 AddNamespaceFkToAuditEventsGroupNamespaceFilters: migrating =
main: -- transaction_open?(nil)
main:    -> 0.0000s
main: -- transaction_open?(nil)
main:    -> 0.0000s
main: -- execute("ALTER TABLE audit_events_streaming_group_namespace_filters ADD CONSTRAINT fk_a1a4486a96 FOREIGN KEY (namespace_id) REFERENCES namespaces (id) ON DELETE CASCADE NOT VALID;")
main:    -> 0.0012s
main: -- execute("SET statement_timeout TO 0")
main:    -> 0.0001s
main: -- execute("ALTER TABLE audit_events_streaming_group_namespace_filters VALIDATE CONSTRAINT fk_a1a4486a96;")
main:    -> 0.0049s
main: -- execute("RESET statement_timeout")
main:    -> 0.0003s
main: == 20240419074648 AddNamespaceFkToAuditEventsGroupNamespaceFilters: migrated (0.0375s) 

main: == [advisory_lock_connection] object_id: 121680, pg_backend_pid: 76506


## down

bundle exec rake db:migrate:down:main VERSION=20240419074648              
main: == [advisory_lock_connection] object_id: 121680, pg_backend_pid: 75961
main: == 20240419074648 AddNamespaceFkToAuditEventsGroupNamespaceFilters: reverting =
main: -- transaction_open?(nil)
main:    -> 0.0000s
main: -- remove_foreign_key(:audit_events_streaming_group_namespace_filters, {:column=>:namespace_id})
main:    -> 0.0025s
main: == 20240419074648 AddNamespaceFkToAuditEventsGroupNamespaceFilters: reverted (0.0288s) 

main: == [advisory_lock_connection] object_id: 121680, pg_backend_pid: 75961

Create table migration


## up

bundle exec rake db:migrate:up:main VERSION=20240419071412
main: == [advisory_lock_connection] object_id: 121680, pg_backend_pid: 77827
main: == 20240419071412 CreateAuditEventsStreamingGroupNamespaceFilters: migrating ==
main: -- create_table(:audit_events_streaming_group_namespace_filters)
main:    -> 0.0055s
main: == 20240419071412 CreateAuditEventsStreamingGroupNamespaceFilters: migrated (0.0153s) 

main: == [advisory_lock_connection] object_id: 121680, pg_backend_pid: 77827

## down

bundle exec rake db:migrate:down:main VERSION=20240419071412              
main: == [advisory_lock_connection] object_id: 121680, pg_backend_pid: 77297
main: == 20240419071412 CreateAuditEventsStreamingGroupNamespaceFilters: reverting ==
main: -- drop_table(:audit_events_streaming_group_namespace_filters)
main:    -> 0.0019s
main: == 20240419071412 CreateAuditEventsStreamingGroupNamespaceFilters: reverted (0.0068s) 

main: == [advisory_lock_connection] object_id: 121680, pg_backend_pid: 77297

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.

How to set up and validate locally

Numbered steps to set up and validate the change are strongly suggested.

Related to #436605 (closed)

Edited by Hitesh Raghuvanshi

Merge request reports

Loading