Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
1
Merge Requests
1
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
gitlab-ce
Commits
e6660ba3
Commit
e6660ba3
authored
Jun 11, 2020
by
Andreas Brandl
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Change primary key definition to bigint
Relates to
https://gitlab.com/gitlab-org/gitlab/-/issues/221091
parent
d231f882
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
39 additions
and
0 deletions
+39
-0
lib/gitlab/database/partitioning_migration_helpers/table_management_helpers.rb
...artitioning_migration_helpers/table_management_helpers.rb
+9
-0
spec/lib/gitlab/database/partitioning_migration_helpers/table_management_helpers_spec.rb
...ioning_migration_helpers/table_management_helpers_spec.rb
+30
-0
No files found.
lib/gitlab/database/partitioning_migration_helpers/table_management_helpers.rb
View file @
e6660ba3
...
...
@@ -109,9 +109,18 @@ module Gitlab
remove_column
(
table_name
,
partition_column
.
name
)
rename_column
(
table_name
,
tmp_column_name
,
partition_column
.
name
)
change_column_default
(
table_name
,
primary_key
,
nil
)
if
column_of_type?
(
table_name
,
primary_key
,
:integer
)
# Default to int8 primary keys to prevent overflow
change_column
(
table_name
,
primary_key
,
:bigint
)
end
end
end
def
column_of_type?
(
table_name
,
column
,
type
)
find_column_definition
(
table_name
,
column
).
type
==
type
end
def
create_daterange_partitions
(
table_name
,
column_name
,
min_date
,
max_date
)
min_date
=
min_date
.
beginning_of_month
.
to_date
max_date
=
max_date
.
next_month
.
beginning_of_month
.
to_date
...
...
spec/lib/gitlab/database/partitioning_migration_helpers/table_management_helpers_spec.rb
View file @
e6660ba3
...
...
@@ -111,6 +111,36 @@ describe Gitlab::Database::PartitioningMigrationHelpers::TableManagementHelpers
expect_table_partitioned_by
(
partitioned_table
,
[
partition_column
])
end
it
'changes the primary key datatype to bigint'
do
migration
.
partition_table_by_date
template_table
,
partition_column
,
min_date:
min_date
,
max_date:
max_date
pk_column
=
connection
.
columns
(
partitioned_table
).
find
{
|
c
|
c
.
name
==
old_primary_key
}
expect
(
pk_column
.
sql_type
).
to
eq
(
'bigint'
)
end
context
'with a non-integer primary key datatype'
do
before
do
connection
.
create_table
:another_example
,
id:
false
do
|
t
|
t
.
string
:identifier
,
primary_key:
true
t
.
timestamp
:created_at
end
end
let
(
:template_table
)
{
:another_example
}
let
(
:old_primary_key
)
{
'identifier'
}
it
'does not change the primary key datatype'
do
migration
.
partition_table_by_date
template_table
,
partition_column
,
min_date:
min_date
,
max_date:
max_date
original_pk_column
=
connection
.
columns
(
template_table
).
find
{
|
c
|
c
.
name
==
old_primary_key
}
pk_column
=
connection
.
columns
(
partitioned_table
).
find
{
|
c
|
c
.
name
==
old_primary_key
}
expect
(
pk_column
).
not_to
be_nil
expect
(
pk_column
).
to
eq
(
original_pk_column
)
end
end
it
'removes the default from the primary key column'
do
migration
.
partition_table_by_date
template_table
,
partition_column
,
min_date:
min_date
,
max_date:
max_date
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment