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
6735e1dc
Commit
6735e1dc
authored
Aug 11, 2017
by
Yorick Peterse
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Document how to handle different DB (versions)
parent
39c5be7a
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
27 additions
and
0 deletions
+27
-0
doc/development/README.md
doc/development/README.md
+1
-0
doc/development/verifying_database_capabilities.md
doc/development/verifying_database_capabilities.md
+26
-0
No files found.
doc/development/README.md
View file @
6735e1dc
...
...
@@ -58,6 +58,7 @@
-
[
Storing SHA1 Hashes As Binary
](
sha1_as_binary.md
)
-
[
Iterating Tables In Batches
](
iterating_tables_in_batches.md
)
-
[
Ordering Table Columns
](
ordering_table_columns.md
)
-
[
Verifying Database Capabilities
](
verifying_database_capabilities.md
)
## i18n
...
...
doc/development/verifying_database_capabilities.md
0 → 100644
View file @
6735e1dc
# Verifying Database Capabilities
Sometimes certain bits of code may only work on a certain database and/or
version. While we try to avoid such code as much as possible sometimes it is
necessary to add database (version) specific behaviour.
To facilitate this we have the following methods that you can use:
*
`Gitlab::Database.postgresql?`
: returns
`true`
if PostgreSQL is being used
*
`Gitlab::Database.mysql?`
: returns
`true`
if MySQL is being used
*
`Gitlab::Database.version`
: returns the PostgreSQL version number as a string
in the format
`X.Y.Z`
. This method does not work for MySQL
This allows you to write code such as:
```
ruby
if
Gitlab
::
Database
.
postgresql?
if
Gitlab
::
Database
.
version
.
to_f
>=
9.6
run_really_fast_query
else
run_fast_query
end
else
run_query
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