-
Notifications
You must be signed in to change notification settings - Fork 24
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
Generate index names less than 63 bytes #94
Conversation
@@ -80,6 +80,16 @@ def unsafe_add_index(table, column_names, options = {}) | |||
raise PgHaMigrations::InvalidMigrationError, "ActiveRecord drops the :opclass option when supplying a string containing an expression or list of columns; instead either supply an array of columns or include the opclass in the string for each column" | |||
end | |||
|
|||
validated_table = PgHaMigrations::Table.from_table_name(table) |
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.
Subtle, but maybe relevant behavior change here. This will raise a PgHaMigrations::UndefinedTableError
instead of bubbling up an error from postgres when the table doesn't exist. I think that's okay...
Oh and I think I missed a test for this. Doing that now
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.
That seems fine.
@@ -96,9 +96,23 @@ def partitions(include_sub_partitions: false, include_self: false) | |||
end | |||
|
|||
class Index < Relation | |||
# TODO: implement shortening to ensure < 63 bytes | |||
MAX_NAME_SIZE = 63 # bytes | |||
|
|||
def self.from_table_and_columns(table, columns) |
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.
This function is always used for constructing a new index name (i.e., as opposed to getting existing indexes)?
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.
Currently yes, although the class itself has a valid?
method which can be used to check for both the existence and validity of an index. This brings up a really good point about the consistency of all of these structs. Like for tables, from_table_name
expects the table to exist (and will raise an error if it doesn't). And the optional lock mode on a relation can be both an existing lock and a future target lock. It might be worthwhile to refactor all of this to be more consistent, although I don't have good sense of how to do that (and it most definitely should be in a different PR)
This was previously in #86, but that only solved the problem for creating partitioned indexes. This more holistically addresses #89
Essentially backports this feature into older versions of Rails