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
0
Merge Requests
0
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
Jérome Perrin
gitlab-ce
Commits
acc22a84
Commit
acc22a84
authored
May 25, 2017
by
Grzegorz Bizon
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Simplify migrations for specific database schema
parent
6d8963e3
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
29 additions
and
162 deletions
+29
-162
config/database.yml.postgresql
config/database.yml.postgresql
+0
-11
db/migrate/20170525132202_migrate_pipeline_stages.rb
db/migrate/20170525132202_migrate_pipeline_stages.rb
+1
-1
db/schema.rb
db/schema.rb
+9
-1
spec/migrations/migrate_pipeline_stages_spec.rb
spec/migrations/migrate_pipeline_stages_spec.rb
+9
-113
spec/migrations_helper.rb
spec/migrations_helper.rb
+0
-36
spec/spec_helper.rb
spec/spec_helper.rb
+10
-0
No files found.
config/database.yml.postgresql
View file @
acc22a84
...
...
@@ -46,14 +46,3 @@ test: &test
username: postgres
password:
# host: localhost
# Warning: The database defined as "migrate" might erased.
# Do not set this db to the same as development or production.
migrate: &test
adapter: postgresql
encoding: unicode
database: gitlabhq_migrate
pool: 5
username: postgres
password:
# host: localhost
db/migrate/20170525132202_migrate_pipeline_stages.rb
View file @
acc22a84
...
...
@@ -8,7 +8,7 @@ class MigratePipelineStages < ActiveRecord::Migration
t
.
integer
:project_id
t
.
integer
:pipeline_id
t
.
string
:name
t
.
timestamps
t
.
timestamps
null:
true
end
end
end
db/schema.rb
View file @
acc22a84
...
...
@@ -11,7 +11,7 @@
#
# It's strongly recommended that you check this file into your version control system.
ActiveRecord
::
Schema
.
define
(
version:
2017052
3091700
)
do
ActiveRecord
::
Schema
.
define
(
version:
2017052
5132202
)
do
# These are extensions that must be enabled in order to support this database
enable_extension
"plpgsql"
...
...
@@ -325,6 +325,14 @@ ActiveRecord::Schema.define(version: 20170523091700) do
add_index
"ci_runners"
,
[
"locked"
],
name:
"index_ci_runners_on_locked"
,
using: :btree
add_index
"ci_runners"
,
[
"token"
],
name:
"index_ci_runners_on_token"
,
using: :btree
create_table
"ci_stages"
,
force: :cascade
do
|
t
|
t
.
integer
"project_id"
t
.
integer
"pipeline_id"
t
.
string
"name"
t
.
datetime
"created_at"
t
.
datetime
"updated_at"
end
create_table
"ci_trigger_requests"
,
force: :cascade
do
|
t
|
t
.
integer
"trigger_id"
,
null:
false
t
.
text
"variables"
...
...
spec/migrations/migrate_pipeline_stages_spec.rb
View file @
acc22a84
require
'
migrations
_helper'
require
'
spec
_helper'
require
Rails
.
root
.
join
(
'db'
,
'migrate'
,
'20170525132202_migrate_pipeline_stages.rb'
)
describe
MigratePipelineStages
,
:migration
do
##
# Create tables using schema from which we will migrate stuff.
#
before
do
ActiveRecord
::
Schema
.
define
(
version:
20170523091700
)
do
enable_extension
"plpgsql"
enable_extension
"pg_trgm"
create_table
"ci_pipelines"
,
force: :cascade
do
|
t
|
t
.
string
"ref"
t
.
string
"sha"
t
.
string
"before_sha"
t
.
datetime
"created_at"
t
.
datetime
"updated_at"
t
.
boolean
"tag"
,
default:
false
t
.
text
"yaml_errors"
t
.
datetime
"committed_at"
t
.
integer
"project_id"
t
.
string
"status"
t
.
datetime
"started_at"
t
.
datetime
"finished_at"
t
.
integer
"duration"
t
.
integer
"user_id"
t
.
integer
"lock_version"
t
.
integer
"auto_canceled_by_id"
t
.
integer
"pipeline_schedule_id"
end
add_index
"ci_pipelines"
,
[
"auto_canceled_by_id"
],
name:
"index_ci_pipelines_on_auto_canceled_by_id"
,
using: :btree
add_index
"ci_pipelines"
,
[
"pipeline_schedule_id"
],
name:
"index_ci_pipelines_on_pipeline_schedule_id"
,
using: :btree
add_index
"ci_pipelines"
,
[
"project_id"
,
"ref"
,
"status"
],
name:
"index_ci_pipelines_on_project_id_and_ref_and_status"
,
using: :btree
add_index
"ci_pipelines"
,
[
"project_id"
,
"sha"
],
name:
"index_ci_pipelines_on_project_id_and_sha"
,
using: :btree
add_index
"ci_pipelines"
,
[
"project_id"
],
name:
"index_ci_pipelines_on_project_id"
,
using: :btree
add_index
"ci_pipelines"
,
[
"status"
],
name:
"index_ci_pipelines_on_status"
,
using: :btree
add_index
"ci_pipelines"
,
[
"user_id"
],
name:
"index_ci_pipelines_on_user_id"
,
using: :btree
create_table
"ci_builds"
,
force: :cascade
do
|
t
|
t
.
string
"status"
t
.
datetime
"finished_at"
t
.
text
"trace"
t
.
datetime
"created_at"
t
.
datetime
"updated_at"
t
.
datetime
"started_at"
t
.
integer
"runner_id"
t
.
float
"coverage"
t
.
integer
"commit_id"
t
.
text
"commands"
t
.
string
"name"
t
.
text
"options"
t
.
boolean
"allow_failure"
,
default:
false
,
null:
false
t
.
string
"stage"
t
.
integer
"trigger_request_id"
t
.
integer
"stage_idx"
t
.
boolean
"tag"
t
.
string
"ref"
t
.
integer
"user_id"
t
.
string
"type"
t
.
string
"target_url"
t
.
string
"description"
t
.
text
"artifacts_file"
t
.
integer
"project_id"
t
.
text
"artifacts_metadata"
t
.
integer
"erased_by_id"
t
.
datetime
"erased_at"
t
.
datetime
"artifacts_expire_at"
t
.
string
"environment"
t
.
integer
"artifacts_size"
,
limit:
8
t
.
string
"when"
t
.
text
"yaml_variables"
t
.
datetime
"queued_at"
t
.
string
"token"
t
.
integer
"lock_version"
t
.
string
"coverage_regex"
t
.
integer
"auto_canceled_by_id"
t
.
boolean
"retried"
end
add_index
"ci_builds"
,
[
"auto_canceled_by_id"
],
name:
"index_ci_builds_on_auto_canceled_by_id"
,
using: :btree
add_index
"ci_builds"
,
[
"commit_id"
,
"stage_idx"
,
"created_at"
],
name:
"index_ci_builds_on_commit_id_and_stage_idx_and_created_at"
,
using: :btree
add_index
"ci_builds"
,
[
"commit_id"
,
"status"
,
"type"
],
name:
"index_ci_builds_on_commit_id_and_status_and_type"
,
using: :btree
add_index
"ci_builds"
,
[
"commit_id"
,
"type"
,
"name"
,
"ref"
],
name:
"index_ci_builds_on_commit_id_and_type_and_name_and_ref"
,
using: :btree
add_index
"ci_builds"
,
[
"commit_id"
,
"type"
,
"ref"
],
name:
"index_ci_builds_on_commit_id_and_type_and_ref"
,
using: :btree
add_index
"ci_builds"
,
[
"project_id"
],
name:
"index_ci_builds_on_project_id"
,
using: :btree
add_index
"ci_builds"
,
[
"runner_id"
],
name:
"index_ci_builds_on_runner_id"
,
using: :btree
add_index
"ci_builds"
,
[
"status"
,
"type"
,
"runner_id"
],
name:
"index_ci_builds_on_status_and_type_and_runner_id"
,
using: :btree
add_index
"ci_builds"
,
[
"status"
],
name:
"index_ci_builds_on_status"
,
using: :btree
add_index
"ci_builds"
,
[
"token"
],
name:
"index_ci_builds_on_token"
,
unique:
true
,
using: :btree
add_index
"ci_builds"
,
[
"updated_at"
],
name:
"index_ci_builds_on_updated_at"
,
using: :btree
add_index
"ci_builds"
,
[
"user_id"
],
name:
"index_ci_builds_on_user_id"
,
using: :btree
end
end
let
(
:pipeline
)
do
Class
.
new
(
ActiveRecord
::
Base
)
do
self
.
table_name
=
'ci_pipelines'
end
end
let
(
:build
)
do
Class
.
new
(
ActiveRecord
::
Base
)
do
self
.
table_name
=
'ci_builds'
end
end
let
(
:stage
)
do
Class
.
new
(
ActiveRecord
::
Base
)
do
self
.
table_name
=
'ci_stages'
end
describe
MigratePipelineStages
,
:migration
,
schema:
20170523091700
do
def
table
(
name
)
Class
.
new
(
ActiveRecord
::
Base
)
{
self
.
table_name
=
name
}
end
##
# Create test data
#
before
do
pipeline
.
create!
(
ref:
'master'
,
sha:
'adf43c3a'
)
table
(
:ci_pipelines
)
.
create!
(
ref:
'master'
,
sha:
'adf43c3a'
)
end
it
'correctly migrates pipeline stages'
do
described_class
.
new
.
change
expect
(
ActiveRecord
::
Base
.
connection
.
table_exists?
(
'ci_stages'
)).
to
eq
false
described_class
.
new
.
migrate
(
:up
)
expect
(
stage
.
table_exists?
).
to
be
true
expect
(
ActiveRecord
::
Base
.
connection
.
table_exists?
(
'ci_stages'
)).
to
eq
true
end
end
spec/migrations_helper.rb
deleted
100644 → 0
View file @
6d8963e3
require
File
.
expand_path
(
"../../config/environment"
,
__FILE__
)
require
'rspec/rails'
require
'shoulda/matchers'
ActiveRecord
::
Base
.
establish_connection
(
:migrate
)
RSpec
.
configure
do
|
config
|
config
.
mock_with
:rspec
config
.
verbose_retry
=
true
config
.
display_try_failure_messages
=
true
config
.
use_transactional_fixtures
=
true
config
.
infer_spec_type_from_file_location!
config
.
raise_errors_for_deprecations!
config
.
around
(
:each
,
:migration
)
do
|
example
|
ActiveRecord
::
Tasks
::
DatabaseTasks
.
purge_current
example
.
run
ActiveRecord
::
Tasks
::
DatabaseTasks
.
purge_current
end
config
.
around
(
:each
,
:redis
)
do
|
example
|
Gitlab
::
Redis
.
with
(
&
:flushall
)
Sidekiq
.
redis
(
&
:flushall
)
example
.
run
Gitlab
::
Redis
.
with
(
&
:flushall
)
Sidekiq
.
redis
(
&
:flushall
)
end
end
puts
"Rails environment:
#{
Rails
.
env
}
"
puts
"Database connection:
#{
ActiveRecord
::
Base
.
connection_config
[
:database
]
}
"
spec/spec_helper.rb
View file @
acc22a84
...
...
@@ -92,6 +92,16 @@ RSpec.configure do |config|
Gitlab
::
Redis
.
with
(
&
:flushall
)
Sidekiq
.
redis
(
&
:flushall
)
end
config
.
around
(
:example
,
migration:
true
)
do
|
example
|
schema_version
=
example
.
metadata
[
:schema
]
migrations_paths
=
ActiveRecord
::
Migrator
.
migrations_paths
ActiveRecord
::
Migrator
.
migrate
(
migrations_paths
,
schema_version
)
example
.
run
ActiveRecord
::
Migration
.
maintain_test_schema!
end
end
FactoryGirl
::
SyntaxRunner
.
class_eval
do
...
...
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