-
Notifications
You must be signed in to change notification settings - Fork 12
Support long reference URLs #203
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,51 @@ | ||
| # This migration comes from co_plan (originally 20260827000000) | ||
| class ExpandCoplanReferenceUrls < ActiveRecord::Migration[8.1] | ||
| def up | ||
| if connection.adapter_name == "PostgreSQL" | ||
| remove_url_index_and_expand_column | ||
| add_digest_column | ||
| add_digest_index | ||
| else | ||
| add_digest_column | ||
| add_digest_index | ||
| remove_url_index_and_expand_column | ||
| end | ||
| end | ||
|
|
||
| def down | ||
| raise ActiveRecord::IrreversibleMigration, | ||
| "reference URLs may exceed the former 255-character limit" | ||
| end | ||
|
|
||
| private | ||
|
|
||
| def add_digest_column | ||
| add_column :coplan_references, :url_digest, :virtual, type: :string, limit: 64, | ||
| as: digest_expression, stored: true | ||
| end | ||
|
|
||
| def add_digest_index | ||
| add_index :coplan_references, [ :plan_id, :url_digest ], unique: true, | ||
| name: "index_coplan_references_on_plan_id_and_url_digest" | ||
| end | ||
|
|
||
| def remove_url_index_and_expand_column | ||
| remove_index :coplan_references, column: [ :plan_id, :url ] | ||
| if connection.adapter_name == "Mysql2" | ||
| execute "ALTER TABLE coplan_references MODIFY url TEXT CHARACTER SET utf8mb4 COLLATE utf8mb4_bin NOT NULL" | ||
| else | ||
| change_column :coplan_references, :url, :text, null: false | ||
| end | ||
| end | ||
|
|
||
| def digest_expression | ||
| case connection.adapter_name | ||
| when "Mysql2" | ||
| "SHA2(url, 256)" | ||
| when "PostgreSQL" | ||
| "encode(sha256(url::bytea), 'hex')" | ||
| else | ||
| raise "Unsupported database adapter: #{connection.adapter_name}" | ||
| end | ||
| end | ||
| end |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,50 @@ | ||
| class ExpandCoplanReferenceUrls < ActiveRecord::Migration[8.1] | ||
| def up | ||
| if connection.adapter_name == "PostgreSQL" | ||
| remove_url_index_and_expand_column | ||
| add_digest_column | ||
| add_digest_index | ||
| else | ||
| add_digest_column | ||
| add_digest_index | ||
| remove_url_index_and_expand_column | ||
| end | ||
| end | ||
|
|
||
| def down | ||
| raise ActiveRecord::IrreversibleMigration, | ||
| "reference URLs may exceed the former 255-character limit" | ||
| end | ||
|
|
||
| private | ||
|
|
||
| def add_digest_column | ||
| add_column :coplan_references, :url_digest, :virtual, type: :string, limit: 64, | ||
| as: digest_expression, stored: true | ||
| end | ||
|
|
||
| def add_digest_index | ||
| add_index :coplan_references, [ :plan_id, :url_digest ], unique: true, | ||
| name: "index_coplan_references_on_plan_id_and_url_digest" | ||
| end | ||
|
|
||
| def remove_url_index_and_expand_column | ||
| remove_index :coplan_references, column: [ :plan_id, :url ] | ||
| if connection.adapter_name == "Mysql2" | ||
| execute "ALTER TABLE coplan_references MODIFY url TEXT CHARACTER SET utf8mb4 COLLATE utf8mb4_bin NOT NULL" | ||
| else | ||
| change_column :coplan_references, :url, :text, null: false | ||
| end | ||
| end | ||
|
|
||
| def digest_expression | ||
| case connection.adapter_name | ||
| when "Mysql2" | ||
| "SHA2(url, 256)" | ||
|
Comment on lines
+42
to
+43
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
On MySQL, AGENTS.md reference: AGENTS.md:L30-L36 Useful? React with 👍 / 👎.
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Updated by Amp 🤖 MySQL now stores reference URLs with a binary collation, matching PostgreSQL’s case-sensitive equality and the byte-sensitive SHA-256 digest while preserving valid case-sensitive URL paths. Fresh migration and schema-load tests cover the contract on both adapters. |
||
| when "PostgreSQL" | ||
| "encode(sha256(url::bytea), 'hex')" | ||
| else | ||
| raise "Unsupported database adapter: #{connection.adapter_name}" | ||
| end | ||
| end | ||
| end | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
On MySQL, each of these DDL statements commits independently, so dropping the original unique index here leaves writes unprotected throughout the subsequent column alteration and digest-index build. If concurrent writers insert the same plan/URL during that window, both model validations can pass and the final
add_index ... unique: truecan fail, leaving this nontransactional migration partially applied. The generated column addresses the previously reported NULL-digest problem, but the updated ordering provides fresh evidence of this separate gap; create the digest unique index immediately after adding the generated column, before removing the old index.AGENTS.md reference: AGENTS.md:L30-L36
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated by Amp 🤖
The generated-digest unique index is now created before the old URL index is removed on MySQL, so every step of its nontransactional DDL sequence retains database-level uniqueness.