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
7f67108a
Commit
7f67108a
authored
May 07, 2018
by
Douwe Maan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add project_mirror_data columns at the appropriate times
parent
c3a8d277
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
49 additions
and
62 deletions
+49
-62
db/migrate/20180502122856_create_project_mirror_data.rb
db/migrate/20180502122856_create_project_mirror_data.rb
+16
-8
ee/db/migrate/20170509153720_create_project_mirror_data_ee.rb
...b/migrate/20170509153720_create_project_mirror_data_ee.rb
+28
-23
ee/db/migrate/20180502124117_add_missing_columns_to_project_mirror_data.rb
...80502124117_add_missing_columns_to_project_mirror_data.rb
+4
-30
ee/db/post_migrate/20180502130136_migrate_mirror_attributes_data_from_projects_to_import_state.rb
...e_mirror_attributes_data_from_projects_to_import_state.rb
+0
-0
ee/spec/migrations/migrate_mirror_attributes_data_from_projects_to_import_state_spec.rb
...ror_attributes_data_from_projects_to_import_state_spec.rb
+1
-1
No files found.
db/migrate/20180502122856_create_project_mirror_data.rb
View file @
7f67108a
...
...
@@ -4,17 +4,25 @@ class CreateProjectMirrorData < ActiveRecord::Migration
DOWNTIME
=
false
def
up
return
if
table_exists?
(
:project_mirror_data
)
create_table
:project_mirror_data
do
|
t
|
t
.
references
:project
,
index:
true
,
foreign_key:
{
on_delete: :cascade
}
t
.
string
:status
t
.
string
:jid
t
.
text
:last_error
if
table_exists?
(
:project_mirror_data
)
add_column
:project_mirror_data
,
:status
,
:string
add_column
:project_mirror_data
,
:jid
,
:string
add_column
:project_mirror_data
,
:last_error
,
:text
else
create_table
:project_mirror_data
do
|
t
|
t
.
references
:project
,
index:
true
,
foreign_key:
{
on_delete: :cascade
}
t
.
string
:status
t
.
string
:jid
t
.
text
:last_error
end
end
end
def
down
drop_table
(
:project_mirror_data
)
if
table_exists?
(
:project_mirror_data
)
remove_column
:project_mirror_data
,
:status
remove_column
:project_mirror_data
,
:jid
remove_column
:project_mirror_data
,
:last_error
# ee/db/migrate/20170509153720_create_project_mirror_data_ee.rb will remove the table.
end
end
ee/db/migrate/20170509153720_create_project_mirror_data_ee.rb
View file @
7f67108a
...
...
@@ -7,29 +7,34 @@ class CreateProjectMirrorDataEE < ActiveRecord::Migration
def
up
# When moving from CE to EE, project_mirror_data may already exist, but will
# not have all the required columns. These are added in AddMissingColumnsToProjectMirrorData.
return
if
table_exists?
(
:project_mirror_data
)
execute
<<-
SQL
CREATE TABLE project_mirror_data
AS (
SELECT id AS project_id,
0 AS retry_count,
CAST(NULL AS
#{
timestamp
}
) AS last_update_started_at,
CAST(NULL AS
#{
timestamp
}
) AS last_update_scheduled_at,
NOW() AS next_execution_timestamp,
NOW() AS created_at,
NOW() AS updated_at
FROM projects
WHERE mirror IS TRUE
);
SQL
add_column
:project_mirror_data
,
:id
,
:primary_key
change_column_default
:project_mirror_data
,
:retry_count
,
0
change_column_null
:project_mirror_data
,
:retry_count
,
false
add_concurrent_foreign_key
:project_mirror_data
,
:projects
,
column: :project_id
add_concurrent_index
:project_mirror_data
,
[
:project_id
],
unique:
true
# not have all the required columns.
if
table_exists?
(
:project_mirror_data
)
add_column_with_default
:project_mirror_data
,
:retry_count
,
:integer
,
default:
0
,
allow_null:
false
add_column
:project_mirror_data
,
:last_update_started_at
,
:datetime_with_timezone
add_column
:project_mirror_data
,
:last_update_scheduled_at
,
:datetime_with_timezone
add_column
:project_mirror_data
,
:next_execution_timestamp
,
:datetime_with_timezone
else
execute
<<-
SQL
CREATE TABLE project_mirror_data
AS (
SELECT id AS project_id,
0 AS retry_count,
CAST(NULL AS
#{
timestamp
}
) AS last_update_started_at,
CAST(NULL AS
#{
timestamp
}
) AS last_update_scheduled_at,
NOW() AS next_execution_timestamp,
NOW() AS created_at,
NOW() AS updated_at
FROM projects
WHERE mirror IS TRUE
);
SQL
add_column
:project_mirror_data
,
:id
,
:primary_key
change_column_default
:project_mirror_data
,
:retry_count
,
0
change_column_null
:project_mirror_data
,
:retry_count
,
false
add_concurrent_foreign_key
:project_mirror_data
,
:projects
,
column: :project_id
add_concurrent_index
:project_mirror_data
,
[
:project_id
],
unique:
true
end
end
def
down
...
...
ee/db/migrate/20180502124117_add_missing_columns_to_project_mirror_data.rb
View file @
7f67108a
...
...
@@ -10,38 +10,12 @@ class AddMissingColumnsToProjectMirrorData < ActiveRecord::Migration
disable_ddl_transaction!
def
up
# Columns missing when a CE instance is upgraded to EE
unless
column_exists?
:project_mirror_data
,
:retry_count
add_column_with_default
:project_mirror_data
,
:retry_count
,
:integer
,
default:
0
,
allow_null:
false
add_column
:project_mirror_data
,
:last_update_started_at
,
:datetime
add_column
:project_mirror_data
,
:last_update_scheduled_at
,
:datetime
add_column
:project_mirror_data
,
:next_execution_timestamp
,
:datetime
end
# Columns missing on an EE instance
unless
column_exists?
:project_mirror_data
,
:status
add_column
:project_mirror_data
,
:status
,
:string
add_column
:project_mirror_data
,
:jid
,
:string
add_column
:project_mirror_data
,
:last_update_at
,
:datetime_with_timezone
add_column
:project_mirror_data
,
:last_successful_update_at
,
:datetime_with_timezone
add_column
:project_mirror_data
,
:last_error
,
:text
end
add_column
:project_mirror_data
,
:last_update_at
,
:datetime_with_timezone
add_column
:project_mirror_data
,
:last_successful_update_at
,
:datetime_with_timezone
end
def
down
if
column_exists?
:project_mirror_data
,
:retry_count
remove_column
:project_mirror_data
,
:retry_count
remove_column
:project_mirror_data
,
:last_update_started_at
remove_column
:project_mirror_data
,
:last_update_scheduled_at
remove_column
:project_mirror_data
,
:next_execution_timestamp
end
if
column_exists?
:project_mirror_data
,
:status
remove_column
:project_mirror_data
,
:status
remove_column
:project_mirror_data
,
:jid
remove_column
:project_mirror_data
,
:last_update_at
remove_column
:project_mirror_data
,
:last_successful_update_at
remove_column
:project_mirror_data
,
:last_error
end
remove_column
:project_mirror_data
,
:last_update_at
remove_column
:project_mirror_data
,
:last_successful_update_at
end
end
ee/db/post_migrate/20180
43018
0136_migrate_mirror_attributes_data_from_projects_to_import_state.rb
→
ee/db/post_migrate/20180
50213
0136_migrate_mirror_attributes_data_from_projects_to_import_state.rb
View file @
7f67108a
File moved
ee/spec/migrations/migrate_mirror_attributes_data_from_projects_to_import_state_spec.rb
View file @
7f67108a
require
'spec_helper'
require
Rails
.
root
.
join
(
'ee'
,
'db'
,
'post_migrate'
,
'20180
43018
0136_migrate_mirror_attributes_data_from_projects_to_import_state.rb'
)
require
Rails
.
root
.
join
(
'ee'
,
'db'
,
'post_migrate'
,
'20180
50213
0136_migrate_mirror_attributes_data_from_projects_to_import_state.rb'
)
describe
MigrateMirrorAttributesDataFromProjectsToImportState
,
:migration
do
let
(
:namespaces
)
{
table
(
:namespaces
)
}
...
...
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