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
Boxiang Sun
gitlab-ce
Commits
564306e0
Commit
564306e0
authored
Jan 30, 2018
by
Nick Thomas
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Don't assume postgresql in two initializers
parent
69a3af73
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
48 additions
and
44 deletions
+48
-44
config/initializers/ar5_pg_10_support.rb
config/initializers/ar5_pg_10_support.rb
+45
-43
config/initializers/peek.rb
config/initializers/peek.rb
+3
-1
No files found.
config/initializers/ar5_pg_10_support.rb
View file @
564306e0
raise
"Vendored ActiveRecord 5 code! Delete
#{
__FILE__
}
!"
if
ActiveRecord
::
VERSION
::
MAJOR
>=
5
raise
"Vendored ActiveRecord 5 code! Delete
#{
__FILE__
}
!"
if
ActiveRecord
::
VERSION
::
MAJOR
>=
5
require
'active_record/connection_adapters/postgresql_adapter'
if
Gitlab
::
Database
.
postgresql?
require
'active_record/connection_adapters/postgresql/schema_statements'
require
'active_record/connection_adapters/postgresql_adapter'
require
'active_record/connection_adapters/postgresql/schema_statements'
#
# Monkey-patch the refused Rails 4.2 patch at https://github.com/rails/rails/pull/31330
#
#
# Monkey-patch the refused Rails 4.2 patch at https://github.com/rails/rails/pull/31330
# Updates sequence logic to support PostgreSQL 10.
#
#
# Updates sequence logic to support PostgreSQL 10.
# rubocop:disable all
#
module
ActiveRecord
# rubocop:disable all
module
ConnectionAdapters
module
ActiveRecord
module
ConnectionAdapters
# We need #postgresql_version to be public as in ActiveRecord 5 for seed_fu
# to work. In ActiveRecord 4, it is protected.
# We need #postgresql_version to be public as in ActiveRecord 5 for seed_fu
# https://github.com/mbleigh/seed-fu/issues/123
# to work. In ActiveRecord 4, it is protected.
class
PostgreSQLAdapter
# https://github.com/mbleigh/seed-fu/issues/123
public
:postgresql_version
class
PostgreSQLAdapter
end
public
:postgresql_version
end
module
PostgreSQL
module
PostgreSQL
module
SchemaStatements
module
SchemaStatements
# Resets the sequence of a table's primary key to the maximum value.
# Resets the sequence of a table's primary key to the maximum value.
def
reset_pk_sequence!
(
table
,
pk
=
nil
,
sequence
=
nil
)
#:nodoc:
def
reset_pk_sequence!
(
table
,
pk
=
nil
,
sequence
=
nil
)
#:nodoc:
unless
pk
and
sequence
unless
pk
and
sequence
default_pk
,
default_sequence
=
pk_and_sequence_for
(
table
)
default_pk
,
default_sequence
=
pk_and_sequence_for
(
table
)
pk
||=
default_pk
pk
||=
default_pk
sequence
||=
default_sequence
sequence
||=
default_sequence
end
end
if
@logger
&&
pk
&&
!
sequence
if
@logger
&&
pk
&&
!
sequence
@logger
.
warn
"
#{
table
}
has primary key
#{
pk
}
with no default sequence"
@logger
.
warn
"
#{
table
}
has primary key
#{
pk
}
with no default sequence"
end
end
if
pk
&&
sequence
if
pk
&&
sequence
quoted_sequence
=
quote_table_name
(
sequence
)
quoted_sequence
=
quote_table_name
(
sequence
)
max_pk
=
select_value
(
"SELECT MAX(
#{
quote_column_name
pk
}
) FROM
#{
quote_table_name
(
table
)
}
"
)
max_pk
=
select_value
(
"SELECT MAX(
#{
quote_column_name
pk
}
) FROM
#{
quote_table_name
(
table
)
}
"
)
if
max_pk
.
nil?
if
max_pk
.
nil?
if
postgresql_version
>=
100000
if
postgresql_version
>=
100000
minvalue
=
select_value
(
"SELECT seqmin FROM pg_sequence WHERE seqrelid =
#{
quote
(
quoted_sequence
)
}
::regclass"
)
minvalue
=
select_value
(
"SELECT seqmin FROM pg_sequence WHERE seqrelid =
#{
quote
(
quoted_sequence
)
}
::regclass"
)
else
else
minvalue
=
select_value
(
"SELECT min_value FROM
#{
quoted_sequence
}
"
)
minvalue
=
select_value
(
"SELECT min_value FROM
#{
quoted_sequence
}
"
)
end
end
end
end
select_value
<<-
end_sql
,
'SCHEMA'
select_value
<<-
end_sql
,
'SCHEMA'
SELECT setval(
#{
quote
(
quoted_sequence
)
}
,
#{
max_pk
?
max_pk
:
minvalue
}
,
#{
max_pk
?
true
:
false
}
)
SELECT setval(
#{
quote
(
quoted_sequence
)
}
,
#{
max_pk
?
max_pk
:
minvalue
}
,
#{
max_pk
?
true
:
false
}
)
end_sql
end_sql
end
end
end
end
end
end
end
end
end
end
end
# rubocop:enable all
end
end
# rubocop:enable all
config/initializers/peek.rb
View file @
564306e0
...
@@ -7,10 +7,12 @@ if Gitlab::Database.mysql?
...
@@ -7,10 +7,12 @@ if Gitlab::Database.mysql?
require
'peek-mysql2'
require
'peek-mysql2'
PEEK_DB_CLIENT
=
::
Mysql2
::
Client
PEEK_DB_CLIENT
=
::
Mysql2
::
Client
PEEK_DB_VIEW
=
Peek
::
Views
::
Mysql2
PEEK_DB_VIEW
=
Peek
::
Views
::
Mysql2
els
e
els
if
Gitlab
::
Database
.
postgresql?
require
'peek-pg'
require
'peek-pg'
PEEK_DB_CLIENT
=
::
PG
::
Connection
PEEK_DB_CLIENT
=
::
PG
::
Connection
PEEK_DB_VIEW
=
Peek
::
Views
::
PG
PEEK_DB_VIEW
=
Peek
::
Views
::
PG
else
raise
"Unsupported database adapter for peek!"
end
end
Peek
.
into
PEEK_DB_VIEW
Peek
.
into
PEEK_DB_VIEW
...
...
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