Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
What's new
8
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Switch to GitLab Next
Sign in
Toggle navigation
Menu
Open sidebar
gitlab-qa-sandbox-group
qa-test-2019-05-06-03-38-42-40f225278db2df81
add-member-project-38ac0d05ff9a6e41
Commits
d1ed3d1c
Commit
d1ed3d1c
authored
Sep 18, 2015
by
Jacob Vosmaer
Browse files
Do DB dumps required for final export
parent
7ac27f1e
Changes
1
Hide whitespace changes
Inline
Side-by-side
lib/backup/database.rb
View file @
d1ed3d1c
...
...
@@ -2,6 +2,13 @@ require 'yaml'
module
Backup
class
Database
TABLES
=
%w{
ci_application_settings ci_builds ci_commits ci_events ci_jobs ci_projects
ci_runner_projects ci_runners ci_services ci_tags ci_taggings ci_trigger_requests
ci_triggers ci_variables ci_web_hooks
}
TABLES
.
map!
{
|
t
|
t
.
sub
(
'ci_'
,
''
)
}
# hack until Kamil's migration lands
attr_reader
:config
,
:db_dir
def
initialize
...
...
@@ -19,11 +26,11 @@ module Backup
dump_pid
=
case
config
[
"adapter"
]
when
/^mysql/
then
$progress
.
print
"Dumping MySQL database
#{
config
[
'database'
]
}
... "
spawn
(
'mysqldump'
,
*
mysql_args
,
config
[
'database'
],
out:
compress_wr
)
spawn
(
'mysqldump'
,
*
mysql_args
,
config
[
'database'
],
*
TABLES
,
out:
compress_wr
)
when
"postgresql"
then
$progress
.
print
"Dumping PostgreSQL database
#{
config
[
'database'
]
}
... "
pg_env
spawn
(
'pg_dump'
,
config
[
'database'
],
out:
compress_wr
)
spawn
(
'pg_dump'
,
'--clean'
,
*
TABLES
.
map
{
|
t
|
"--table=
#{
t
}
"
},
config
[
'database'
],
out:
compress_wr
)
end
compress_wr
.
close
...
...
@@ -44,10 +51,6 @@ module Backup
spawn
(
'mysql'
,
*
mysql_args
,
config
[
'database'
],
in:
decompress_rd
)
when
"postgresql"
then
$progress
.
print
"Restoring PostgreSQL database
#{
config
[
'database'
]
}
... "
# Drop all tables because PostgreSQL DB dumps do not contain DROP TABLE
# statements like MySQL.
drop_all_tables
drop_all_postgres_sequences
pg_env
spawn
(
'psql'
,
config
[
'database'
],
in:
decompress_rd
)
end
...
...
@@ -91,19 +94,5 @@ module Backup
$progress
.
puts
'[FAILED]'
.
red
end
end
def
drop_all_tables
connection
=
ActiveRecord
::
Base
.
connection
connection
.
tables
.
each
do
|
table
|
connection
.
drop_table
(
table
)
end
end
def
drop_all_postgres_sequences
connection
=
ActiveRecord
::
Base
.
connection
connection
.
execute
(
"SELECT c.relname FROM pg_class c WHERE c.relkind = 'S';"
).
each
do
|
sequence
|
connection
.
execute
(
"DROP SEQUENCE
#{
sequence
[
'relname'
]
}
"
)
end
end
end
end
Write
Preview
Supports
Markdown
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