Add legacy_destination_ref column and mappable concern
What does this MR do and why?
While we are in the in-between stage of migrating from the old audit event destination models and the new ones, we need a link between the different kinds of models, to map to our new ones.
This MR adds a legacy_destination_ref to both new audit event streaming destination models, as an integer.
The integer will represent an ID (PK) from either:
- HTTP: AuditEvents::InstanceExternalAuditEventDestination, AuditEvents::ExternalAuditEventDestination
- AWS: AuditEvents::Instance::AmazonS3Configuration, AuditEvents::AmazonS3Configuration
- GCP: AuditEvents::Instance::GoogleCloudLoggingConfiguration, AuditEvents:GoogleCloudLoggingConfiguration
In the two new models: AuditEvents::Instance::ExternalStreamingDestination,AuditEvents::Group::ExternalStreamingDestination
I've added a new LegacyDestinationMappable concern that will map the category of the current model and the id back to the correct old model:
category (http/aws/gcp) + group/instance is enough to distinguish an answer of those 6 models.
In the future when we deprecate the old models and remove old code, we'll just drop the columns and remove the concern.
This migration DOES NOT include a backfill of old existing records, as that will be done in another issue/MR. There will be future work for when these old models are created, that we also create the new models, with this legacy_destination_ref populated.
References
How to set up and validate locally
- Checkout the branch and migrate (to add the two new columns)
- Enter rails console
- Create a destination (old) like
legacy_http = AuditEvents::InstanceExternalAuditEventDestination.create!(name: "Test", destination_url: "https://gitlab.com") - Create a new destination, with a
legacy_destination_refof the one we just created:new_http = AuditEvents::Instance::ExternalStreamingDestination.create!(name: "Test", category: :http, legacy_destination_ref: legacy_http.id, config: { url: "https://gitlab.com" }) - Check
new_http.legacy_destinationandnew_http.legacy_destination_ref(eq new_http.legacy_destionation.id) - Do this for group/instance + aws/http/gcp until satisfied
Example Console Output:
legacy_http = AuditEvents::InstanceExternalAuditEventDestination.create!(name: "Test", destination_url: "https://gitlab.com")
=> #<AuditEvents::InstanceExternalAuditEventDestination:0x0000000156cb4740
id: 2,
created_at: Mon, 11 Nov 2024 20:44:10.670572000 UTC +00:00,
updated_at: Mon, 11 Nov 2024 20:44:10.670572000 UTC +00:00,
destination_url: "https://gitlab.com",
encrypted_verification_token: "[FILTERED]",
encrypted_verification_token_iv: "\x89\x18\xEEj(\xF1\x92\xF7J\xA1\x83\xF3",
name: "Test",
verification_token: nil
new_http = AuditEvents::Instance::ExternalStreamingDestination.create!(name: "Test", category: :http, legacy_destination_ref: legacy_http.id, config: { url: "https://example.com" })
=> #<AuditEvents::Instance::ExternalStreamingDestination:0x000000016b810eb8
id: 2,
created_at: Mon, 11 Nov 2024 20:44:20.570798000 UTC +00:00,
updated_at: Mon, 11 Nov 2024 20:44:20.570798000 UTC +00:00,
category: "http",
name: "Test",
config: {"url"=>"https://example.com"},
encrypted_secret_token: "[FILTERED]",
encrypted_secret_token_iv: "[FILTERED]",
legacy_destination_ref: 2,
secret_token: nil>
> new_http.legacy_destination
=> #<AuditEvents::InstanceExternalAuditEventDestination:0x0000000156c1a280
id: 2,
created_at: Mon, 11 Nov 2024 20:44:10.670572000 UTC +00:00,
updated_at: Mon, 11 Nov 2024 20:44:10.670572000 UTC +00:00,
destination_url: "https://gitlab.com",
encrypted_verification_token: "[FILTERED]",
encrypted_verification_token_iv: "\x89\x18\xEEj(\xF1\x92\xF7J\xA1\x83\xF3",
name: "Test",
verification_token: nil>