BigW Consortium Gitlab
Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
G
gitlab-ce
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
Forest Godfrey
gitlab-ce
Commits
fcaf89a1
Commit
fcaf89a1
authored
Jan 17, 2018
by
Francisco Javier López
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Applied fix
parent
f351cc28
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
87 additions
and
4 deletions
+87
-4
20171215113714_populate_can_push_from_deploy_keys_projects.rb
...1215113714_populate_can_push_from_deploy_keys_projects.rb
+22
-2
20171215121205_post_populate_can_push_from_deploy_keys_projects.rb
...21205_post_populate_can_push_from_deploy_keys_projects.rb
+22
-2
populate_can_push_from_deploy_keys_projects_spec.rb
...tions/populate_can_push_from_deploy_keys_projects_spec.rb
+43
-0
No files found.
db/migrate/20171215113714_populate_can_push_from_deploy_keys_projects.rb
View file @
fcaf89a1
...
@@ -6,6 +6,8 @@ class PopulateCanPushFromDeployKeysProjects < ActiveRecord::Migration
...
@@ -6,6 +6,8 @@ class PopulateCanPushFromDeployKeysProjects < ActiveRecord::Migration
# Set this constant to true if this migration requires downtime.
# Set this constant to true if this migration requires downtime.
DOWNTIME
=
false
DOWNTIME
=
false
DATABASE_NAME
=
Gitlab
::
Database
.
database_name
disable_ddl_transaction!
disable_ddl_transaction!
class
DeploysKeyProject
<
ActiveRecord
::
Base
class
DeploysKeyProject
<
ActiveRecord
::
Base
...
@@ -18,7 +20,15 @@ class PopulateCanPushFromDeployKeysProjects < ActiveRecord::Migration
...
@@ -18,7 +20,15 @@ class PopulateCanPushFromDeployKeysProjects < ActiveRecord::Migration
DeploysKeyProject
.
each_batch
(
of:
10_000
)
do
|
batch
|
DeploysKeyProject
.
each_batch
(
of:
10_000
)
do
|
batch
|
start_id
,
end_id
=
batch
.
pluck
(
'MIN(id), MAX(id)'
).
first
start_id
,
end_id
=
batch
.
pluck
(
'MIN(id), MAX(id)'
).
first
execute
<<-
EOF
if
Gitlab
::
Database
.
mysql?
execute
<<-
EOF
.
strip_heredoc
UPDATE deploy_keys_projects,
#{
DATABASE_NAME
}
.keys
SET deploy_keys_projects.can_push =
#{
DATABASE_NAME
}
.keys.can_push
WHERE deploy_keys_projects.deploy_key_id =
#{
DATABASE_NAME
}
.keys.id
AND deploy_keys_projects.id BETWEEN
#{
start_id
}
AND
#{
end_id
}
EOF
else
execute
<<-
EOF
.
strip_heredoc
UPDATE deploy_keys_projects
UPDATE deploy_keys_projects
SET can_push = keys.can_push
SET can_push = keys.can_push
FROM keys
FROM keys
...
@@ -27,12 +37,21 @@ class PopulateCanPushFromDeployKeysProjects < ActiveRecord::Migration
...
@@ -27,12 +37,21 @@ class PopulateCanPushFromDeployKeysProjects < ActiveRecord::Migration
EOF
EOF
end
end
end
end
end
def
down
def
down
DeploysKeyProject
.
each_batch
(
of:
10_000
)
do
|
batch
|
DeploysKeyProject
.
each_batch
(
of:
10_000
)
do
|
batch
|
start_id
,
end_id
=
batch
.
pluck
(
'MIN(id), MAX(id)'
).
first
start_id
,
end_id
=
batch
.
pluck
(
'MIN(id), MAX(id)'
).
first
execute
<<-
EOF
if
Gitlab
::
Database
.
mysql?
execute
<<-
EOF
.
strip_heredoc
UPDATE deploy_keys_projects,
#{
DATABASE_NAME
}
.keys
SET
#{
DATABASE_NAME
}
.keys.can_push = deploy_keys_projects.can_push
WHERE deploy_keys_projects.deploy_key_id =
#{
DATABASE_NAME
}
.keys.id
AND deploy_keys_projects.id BETWEEN
#{
start_id
}
AND
#{
end_id
}
EOF
else
execute
<<-
EOF
.
strip_heredoc
UPDATE keys
UPDATE keys
SET can_push = deploy_keys_projects.can_push
SET can_push = deploy_keys_projects.can_push
FROM deploy_keys_projects
FROM deploy_keys_projects
...
@@ -41,4 +60,5 @@ class PopulateCanPushFromDeployKeysProjects < ActiveRecord::Migration
...
@@ -41,4 +60,5 @@ class PopulateCanPushFromDeployKeysProjects < ActiveRecord::Migration
EOF
EOF
end
end
end
end
end
end
end
db/post_migrate/20171215121205_post_populate_can_push_from_deploy_keys_projects.rb
View file @
fcaf89a1
...
@@ -5,6 +5,8 @@ class PostPopulateCanPushFromDeployKeysProjects < ActiveRecord::Migration
...
@@ -5,6 +5,8 @@ class PostPopulateCanPushFromDeployKeysProjects < ActiveRecord::Migration
include
Gitlab
::
Database
::
MigrationHelpers
include
Gitlab
::
Database
::
MigrationHelpers
DOWNTIME
=
false
DOWNTIME
=
false
DATABASE_NAME
=
Gitlab
::
Database
.
database_name
disable_ddl_transaction!
disable_ddl_transaction!
class
DeploysKeyProject
<
ActiveRecord
::
Base
class
DeploysKeyProject
<
ActiveRecord
::
Base
...
@@ -17,7 +19,15 @@ class PostPopulateCanPushFromDeployKeysProjects < ActiveRecord::Migration
...
@@ -17,7 +19,15 @@ class PostPopulateCanPushFromDeployKeysProjects < ActiveRecord::Migration
DeploysKeyProject
.
each_batch
(
of:
10_000
)
do
|
batch
|
DeploysKeyProject
.
each_batch
(
of:
10_000
)
do
|
batch
|
start_id
,
end_id
=
batch
.
pluck
(
'MIN(id), MAX(id)'
).
first
start_id
,
end_id
=
batch
.
pluck
(
'MIN(id), MAX(id)'
).
first
execute
<<-
EOF
if
Gitlab
::
Database
.
mysql?
execute
<<-
EOF
.
strip_heredoc
UPDATE deploy_keys_projects,
#{
DATABASE_NAME
}
.keys
SET deploy_keys_projects.can_push =
#{
DATABASE_NAME
}
.keys.can_push
WHERE deploy_keys_projects.deploy_key_id =
#{
DATABASE_NAME
}
.keys.id
AND deploy_keys_projects.id BETWEEN
#{
start_id
}
AND
#{
end_id
}
EOF
else
execute
<<-
EOF
.
strip_heredoc
UPDATE deploy_keys_projects
UPDATE deploy_keys_projects
SET can_push = keys.can_push
SET can_push = keys.can_push
FROM keys
FROM keys
...
@@ -26,12 +36,21 @@ class PostPopulateCanPushFromDeployKeysProjects < ActiveRecord::Migration
...
@@ -26,12 +36,21 @@ class PostPopulateCanPushFromDeployKeysProjects < ActiveRecord::Migration
EOF
EOF
end
end
end
end
end
def
down
def
down
DeploysKeyProject
.
each_batch
(
of:
10_000
)
do
|
batch
|
DeploysKeyProject
.
each_batch
(
of:
10_000
)
do
|
batch
|
start_id
,
end_id
=
batch
.
pluck
(
'MIN(id), MAX(id)'
).
first
start_id
,
end_id
=
batch
.
pluck
(
'MIN(id), MAX(id)'
).
first
execute
<<-
EOF
if
Gitlab
::
Database
.
mysql?
execute
<<-
EOF
.
strip_heredoc
UPDATE deploy_keys_projects,
#{
DATABASE_NAME
}
.keys
SET
#{
DATABASE_NAME
}
.keys.can_push = deploy_keys_projects.can_push
WHERE deploy_keys_projects.deploy_key_id =
#{
DATABASE_NAME
}
.keys.id
AND deploy_keys_projects.id BETWEEN
#{
start_id
}
AND
#{
end_id
}
EOF
else
execute
<<-
EOF
.
strip_heredoc
UPDATE keys
UPDATE keys
SET can_push = deploy_keys_projects.can_push
SET can_push = deploy_keys_projects.can_push
FROM deploy_keys_projects
FROM deploy_keys_projects
...
@@ -40,4 +59,5 @@ class PostPopulateCanPushFromDeployKeysProjects < ActiveRecord::Migration
...
@@ -40,4 +59,5 @@ class PostPopulateCanPushFromDeployKeysProjects < ActiveRecord::Migration
EOF
EOF
end
end
end
end
end
end
end
spec/migrations/populate_can_push_from_deploy_keys_projects_spec.rb
0 → 100644
View file @
fcaf89a1
require
'spec_helper'
require
Rails
.
root
.
join
(
'db'
,
'migrate'
,
'20171215113714_populate_can_push_from_deploy_keys_projects.rb'
)
describe
PopulateCanPushFromDeployKeysProjects
,
:migration
do
let
(
:migration
)
{
described_class
.
new
}
let
(
:deploy_keys
)
{
table
(
:keys
)
}
let
(
:deploy_keys_projects
)
{
table
(
:deploy_keys_projects
)
}
let
(
:projects
)
{
table
(
:projects
)
}
before
do
deploy_keys
.
inheritance_column
=
nil
projects
.
create!
(
id:
1
,
name:
'gitlab1'
,
path:
'gitlab1'
)
(
1
..
10
).
each
do
|
index
|
deploy_keys
.
create!
(
id:
index
,
title:
'dummy'
,
type:
'DeployKey'
,
key:
Spec
::
Support
::
Helpers
::
KeyGeneratorHelper
.
new
(
1024
).
generate
+
' dummy@gitlab.com'
)
deploy_keys_projects
.
create!
(
id:
index
,
deploy_key_id:
index
,
project_id:
1
)
end
end
describe
'#up'
do
it
'migrates can_push from deploy_keys to deploy_keys_projects'
do
deploy_keys
.
limit
(
5
).
update_all
(
can_push:
true
)
expected
=
deploy_keys
.
order
(
:id
).
pluck
(
:id
,
:can_push
)
migration
.
up
expect
(
deploy_keys_projects
.
order
(
:id
).
pluck
(
:deploy_key_id
,
:can_push
)).
to
eq
expected
end
end
describe
'#down'
do
it
'migrates can_push from deploy_keys_projects to deploy_keys'
do
deploy_keys_projects
.
limit
(
5
).
update_all
(
can_push:
true
)
expected
=
deploy_keys_projects
.
order
(
:id
).
pluck
(
:deploy_key_id
,
:can_push
)
migration
.
down
expect
(
deploy_keys
.
order
(
:id
).
pluck
(
:id
,
:can_push
)).
to
eq
expected
end
end
end
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