Commit Graph

160 Commits

Author SHA1 Message Date
GitLab Bot ed01bf9b25 Add latest changes from gitlab-org/gitlab@master 2021-08-13 03:10:09 +00:00
GitLab Bot 07e0fae35c Add latest changes from gitlab-org/gitlab@master 2021-08-06 15:10:05 +00:00
GitLab Bot 5147cd60f1 Add latest changes from gitlab-org/gitlab@master 2021-08-05 12:09:57 +00:00
GitLab Bot 1930898566 Add latest changes from gitlab-org/gitlab@master 2021-08-02 09:10:09 +00:00
GitLab Bot f4d51a9f71 Add latest changes from gitlab-org/gitlab@master 2021-07-29 15:09:48 +00:00
GitLab Bot 228eb2ee91 Add latest changes from gitlab-org/gitlab@master 2021-07-23 15:09:21 +00:00
GitLab Bot 8e0dafbb66 Add latest changes from gitlab-org/gitlab@master 2021-07-22 09:08:22 +00:00
GitLab Bot 1613500bf7 Add latest changes from gitlab-org/gitlab@master 2021-07-09 09:09:53 +00:00
GitLab Bot e1e58fabfa Add latest changes from gitlab-org/gitlab@master 2021-07-07 15:07:24 +00:00
GitLab Bot 8f016fe5fb Add latest changes from gitlab-org/gitlab@master 2021-06-28 21:10:13 +00:00
GitLab Bot 3eb814543a Add latest changes from gitlab-org/gitlab@master 2021-06-22 00:07:53 +00:00
GitLab Bot 83d921d51b Add latest changes from gitlab-org/gitlab@master 2021-06-15 21:10:04 +00:00
GitLab Bot f69bc1dab5 Add latest changes from gitlab-org/gitlab@master 2021-06-14 18:10:28 +00:00
GitLab Bot 81f257d72e Add latest changes from gitlab-org/gitlab@master 2021-06-14 15:09:48 +00:00
GitLab Bot b3e13e0dfd Add latest changes from gitlab-org/gitlab@master 2021-06-02 06:09:48 +00:00
GitLab Bot 926711e454 Add latest changes from gitlab-org/gitlab@master 2021-06-02 00:09:56 +00:00
GitLab Bot 03c84e0de5 Add latest changes from gitlab-org/gitlab@master 2021-05-27 06:10:47 +00:00
GitLab Bot 1cb90c3b4f Add latest changes from gitlab-org/gitlab@master 2021-05-20 18:10:33 +00:00
GitLab Bot 3c988b99e6 Add latest changes from gitlab-org/gitlab@master 2021-05-13 03:10:19 +00:00
GitLab Bot 0ae8428c8e Add latest changes from gitlab-org/gitlab@master 2021-05-11 21:10:21 +00:00
GitLab Bot b7eed2ea49 Add latest changes from gitlab-org/gitlab@master 2021-05-11 06:10:29 +00:00
GitLab Bot 05b83be3ee Add latest changes from gitlab-org/gitlab@master 2021-05-07 15:10:39 +00:00
GitLab Bot a28eb91c64 Add latest changes from gitlab-org/gitlab@master 2021-04-27 21:10:09 +00:00
GitLab Bot e5e0589e09 Add latest changes from gitlab-org/gitlab@master 2021-04-26 12:09:44 +00:00
GitLab Bot a0213db466 Add latest changes from gitlab-org/gitlab@master 2021-03-15 18:09:05 +00:00
GitLab Bot d2091d1e92 Add latest changes from gitlab-org/gitlab@master 2021-03-10 15:09:11 +00:00
GitLab Bot 6559f0ee67 Add latest changes from gitlab-org/gitlab@master 2020-10-19 12:09:20 +00:00
GitLab Bot ec18750aa8 Add latest changes from gitlab-org/gitlab@master 2020-10-05 18:08:51 +00:00
GitLab Bot 91ef4dcc05 Add latest changes from gitlab-org/gitlab@master 2020-10-02 06:08:27 +00:00
GitLab Bot 537882ad40 Add latest changes from gitlab-org/gitlab@master 2020-09-10 00:08:32 +00:00
GitLab Bot c7a46b0419 Add latest changes from gitlab-org/gitlab@master 2020-08-21 00:10:44 +00:00
GitLab Bot a39371aad9 Add latest changes from gitlab-org/gitlab@master 2020-08-19 12:10:17 +00:00
GitLab Bot 7866b83bf4 Add latest changes from gitlab-org/gitlab@master 2020-08-19 09:09:58 +00:00
GitLab Bot 18da92341d Add latest changes from gitlab-org/gitlab@master 2020-08-17 18:10:01 +00:00
GitLab Bot 71da5de44f Add latest changes from gitlab-org/gitlab@master 2020-08-05 15:09:59 +00:00
GitLab Bot ed00b1a6a3 Add latest changes from gitlab-org/gitlab@master 2020-07-28 12:09:49 +00:00
GitLab Bot 448ff1fb83 Add latest changes from gitlab-org/gitlab@master 2020-07-22 03:09:40 +00:00
GitLab Bot f9cda7671c Add latest changes from gitlab-org/gitlab@master 2020-07-14 21:09:03 +00:00
GitLab Bot fcda041fc0 Add latest changes from gitlab-org/gitlab@master 2020-07-09 12:08:56 +00:00
GitLab Bot c52b72f577 Add latest changes from gitlab-org/gitlab@master 2020-07-08 12:09:33 +00:00
GitLab Bot 4d8bd36aa2 Add latest changes from gitlab-org/gitlab@master 2020-07-07 03:09:32 +00:00
GitLab Bot 2a53c24c51 Add latest changes from gitlab-org/gitlab@master 2020-06-26 15:08:45 +00:00
GitLab Bot 5d6119a1a4 Add latest changes from gitlab-org/gitlab@master 2020-06-25 00:09:26 +00:00
GitLab Bot 72721699f1 Add latest changes from gitlab-org/gitlab@master 2020-02-18 00:09:20 +00:00
GitLab Bot 6b9d3a4e83 Add latest changes from gitlab-org/gitlab@master 2020-01-29 18:08:47 +00:00
GitLab Bot 96b0c1245c Add latest changes from gitlab-org/gitlab@master 2020-01-10 12:07:47 +00:00
GitLab Bot cfc792b9ca Add latest changes from gitlab-org/gitlab@master 2019-12-10 07:53:40 +00:00
GitLab Bot b4e072cbaf Add latest changes from gitlab-org/gitlab@master 2019-10-11 06:06:27 +00:00
GitLab Bot 80f61b4035 Add latest changes from gitlab-org/gitlab@master 2019-09-18 14:02:45 +00:00
GitLab Bot b7dfe2ae40 Add latest changes from gitlab-org/gitlab@master 2019-09-13 13:26:31 +00:00
Robert Speicher 7698d40550
Merge branch 'master' of dev.gitlab.org:gitlab/gitlabhq 2019-08-29 17:17:37 -05:00
Tiger 08fcb2379e CE port: allow SRV records in DB service discovery 2019-08-23 14:19:51 +10:00
Alexandru Croitor 5af535d919 Limit the size of issuable description and comments
Limiting the size of issuable description and comments to 1_000_000,
which is close to ~1MB of ASCII characters, which represents 99.9% of
all descriptions and comments we have in DB at the moment. This should
help prevent DoS attacks when comments contain refference strings.

Also this change updates regexp matching the namespaces paths by
limiting the namespaces paths to Namespace::NUMBER_OF_ANCESTORS_ALLOWED,
as we allow 20 levels deep groups.

see https://gitlab.com/gitlab-org/gitlab-ce/issues/61974#note_191274234
2019-08-22 10:43:13 +03:00
Andreas Brandl 988dc80585
Further remove code branches by database type
We dropped MySQL support and a lot of mysql specific code has been
removed in https://gitlab.com/gitlab-org/gitlab-ce/merge_requests/29608.

This comes in from the other direction and removes any `if postgresql?`
branches.
2019-07-29 12:47:06 +02:00
Nick Thomas 4aa76dddec
Remove dead MySQL code
None of this code can be reached any more, so it can all be removed
2019-07-23 16:53:03 +01:00
Andreas Brandl e13f07f195 Merge branch 'js-specs-transactions' into 'master'
Use transactions in JS feature specs

Closes #60207

See merge request gitlab-org/gitlab-ce!27496
2019-07-12 13:30:42 +00:00
Heinrich Lee Yu d4a919679a Use transactions in JS feature specs
Uses Rails transactional tests instead of DatabaseCleaner
transaction strategy because that doesn't work with JS tests
2019-07-12 10:39:14 +08:00
Heinrich Lee Yu aeb67dd489 Upgrade to Rails 5.2
Updates changed method names and fixes spec failures
2019-07-12 10:15:31 +08:00
Mayra Cabrera 0ab89d8e36 Add a rubocop for Rails.logger
Suggests to use a JSON structured log instead

Related to https://gitlab.com/gitlab-org/gitlab-ce/issues/54102
2019-07-10 19:26:47 +00:00
DJ Mountney af28465556 Fix extra newline left by conflict resolution 2019-06-28 16:28:45 +00:00
DJ Mountney c1b1a1fb5e Merge branch 'master' into 'check-min-schema-migrate'
# Conflicts:
#   lib/gitlab/database.rb
2019-06-28 16:27:39 +00:00
Andrew Newdigate 56ae34e49b Adds metrics to measure database transactions
Currently we don't have good insight into the affect of Rails
transaction blocks on the application. If these blocks are held open for
extended periods, they can have detrimental effects on the application.

This change will allow us to track these transactions, with the aim
of reducing their duration.
2019-06-28 12:46:51 +02:00
DJ Mountney de93bf1fbb Update comments and docs around min schema version
Fixed some spelling
Dropped rake task description for a prefix only task
Added note on skipping the check to the postgres debugging dev doc
2019-06-25 10:44:40 -07:00
DJ Mountney f4e1553519 Move min schema version check to db:migrate
Rather than have it checked only as part of gitlab:db:configure, we will
instead have it as a pre-req for every db:migrate command
2019-06-25 10:44:40 -07:00
DJ Mountney 7a089438fa Check supported version when migrating
Set the mininum supported migration version to be the schema version as
of 11.11.0, and errors you if that is not detected during
gitlab:db:configure
2019-06-25 10:44:40 -07:00
Andrew Newdigate 84cb1bdaed Refactor inside_transaction? to Gitlab::Database
This is a small change to move AfterCommitQueue.inside_transaction?
to Gitlab::Database.inside_transaction? Since this change is required
by different changes which may not arrive in sequence, it's easier
to extract this change out on it's own.
2019-06-25 09:15:35 +00:00
Douglas Barbosa Alexandre a86f48c79b
Add helper method to return a human-friendly name for database adapter 2019-03-21 19:03:26 -03:00
Ash McKenzie 26134eeece Rename pg_stat_wal_receiver_supported? DB helper
From pg_stat_wal_receiver_supported? to
postgresql_minimum_supported_version?

Also add test coverage
2019-03-14 15:25:05 +00:00
Jasper Maes 56296f1eda Remove rails4 specific code 2018-12-16 10:48:41 +01:00
Douglas Barbosa Alexandre 5f8423dd85
CE port of 'Move EE specific code from Gitbab::Database into ee' 2018-11-26 17:14:05 -02:00
gfyoung c858f70d07 Enable frozen string for lib/gitlab/*.rb 2018-10-22 07:00:50 +00:00
DJ Mountney 76cfe4f1fd Ensure the schema is loaded with post_migrations included
If doing a schema load, the post_migrations should also be marked as up,
even if SKIP_POST_DEPLOYMENT_MIGRATIONS was set, otherwise future
migration runs will be broken.
2018-09-11 18:41:14 -07:00
Yorick Peterse 2ade035eb2
Backport various EE changes to Gitlab::Database
These changes are useful for CE as well. For example, the MR
https://gitlab.com/gitlab-org/gitlab-ce/merge_requests/20720 can make
use of some of the backported methods.
2018-07-24 13:25:01 +02:00
Brett Walker fd2ea94f60 Ability to check if underlying database is read only 2018-07-06 17:07:49 +00:00
Jarka Kadlecová fa36101a7f Use data_source_exists? instead of table_exists?
Use data_source_exists? where possible instead of table_exists? in order to be Rails5 compatible
2018-06-14 08:39:43 +02:00
Yorick Peterse 63c58a6dd0
Memoize Gitlab::Database.version
This removes the need for running a database query every time we want to
check the database version.
2018-05-17 21:23:42 +02:00
Stan Hu 272783be20 Cache table_exists?('application_settings') to reduce repeated schema reloads
Closes #43355
2018-03-15 13:13:00 -07:00
Stan Hu 4acbc9410d Cache column_exists? for application settings
This is most a backport of
https://gitlab.com/gitlab-org/gitlab-ee/merge_requests/4987/diffs but includes
other columns that use column_exists? in a way that may cause unnecessary
schema loads.
2018-03-15 12:51:39 -07:00
Stan Hu 29e39e55c3 Merge branch 'mk-add-old-attachments-to-uploads-table' into 'master'
Add old files to uploads table

See merge request gitlab-org/gitlab-ce!15270
2017-12-07 02:34:58 +00:00
Brett Walker 02d97d4621 add Gitlab::Database.replication_slots_supported? 2017-12-05 16:43:47 +00:00
Michael Kozono e5cf23dfcf Ensure consistent column order 2017-12-01 15:26:42 -08:00
Michael Kozono 3694fe0f3d Don’t quote `NOW()` for created_at column
To fix for MySQL.
2017-12-01 15:26:42 -08:00
Yorick Peterse bda30182e0
Add returning IDs to Gitlab::Database.bulk_insert
This adds the keyword argument "return_ids" to
Gitlab::Database.bulk_insert. When set to `true` (and PostgreSQL is
used) this method will return an Array of the IDs of the inserted rows,
otherwise it will return an empty Array.
2017-11-07 22:28:57 +01:00
Alejandro Rodríguez 1796936abc Handle large values on `MergeRequestDiffCommit` dates 2017-10-30 21:13:39 -03:00
Toon Claes d13669716a Create idea of read-only database
In GitLab EE, a GitLab instance can be read-only (e.g. when it's a Geo
secondary node). But in GitLab CE it also might be useful to have the
"read-only" idea around. So port it back to GitLab CE.

Also having the principle of read-only in GitLab CE would hopefully
lead to less errors introduced, doing write operations when there
aren't allowed for read-only calls.

Closes gitlab-org/gitlab-ce#37534.
2017-10-06 22:37:40 +02:00
Yorick Peterse 5eab624d3c
Improve migrations using triggers
This adds a bunch of checks to migrations that may create or drop
triggers. Dropping triggers/functions is done using "IF EXISTS" so we
don't throw an error if the object in question has already been dropped.
We now also raise a custom error (message) when the user does not have
TRIGGER privileges. This should prevent the schema from entering an
inconsistent state while also providing the user with enough information
on how to solve the problem.

The recommendation of using SUPERUSER permissions is a bit extreme but
we require this anyway (Omnibus also configures users with this
permission).

Fixes https://gitlab.com/gitlab-org/gitlab-ce/issues/36633
2017-08-29 13:02:44 +02:00
Yorick Peterse aac1de46c9
Use a specialized class for querying events
This changes various controllers to use the new EventCollection class
for retrieving events. This class uses a JOIN LATERAL query on
PostgreSQL to retrieve queries in a more efficient way, while falling
back to a simpler / less efficient query for MySQL.

The EventCollection class also includes a limit on the number of events
to display to prevent malicious users from cycling through all events,
as doing so could put a lot of pressure on the database.

JOIN LATERAL is only supported on PostgreSQL starting with version 9.3.0
and as such this optimisation is only used when using PostgreSQL 9.3 or
newer.
2017-08-10 17:45:49 +02:00
Sean McGivern d4a3474b9b Fix Gitlab::Database.bulk_insert for non-UTF-8 data 2017-06-26 17:21:40 +01:00
Sean McGivern 9a73b634ab Add table for files in merge request diffs
This adds an ID-less table containing one row per file, per merge request
diff. It has a column for each attribute on Gitlab::Git::Diff that is serialised
currently, with the advantage that we can easily query the attributes of this
new table.

It does not migrate existing data, so we have fallback code when the legacy
st_diffs column is present instead. For a merge request diff to be valid, it
should have at most one of:

* Rows in this new table, with the correct merge_request_diff_id.
* A non-NULL st_diffs column.

It may have neither, if the diff is empty.
2017-06-16 18:30:01 +01:00
Tiago Botelho c41df67676 removes redundant code from database.rb 2017-04-11 20:20:19 +01:00
Yorick Peterse 9a20ff1c99
Added Gitlab::Database.config
This returns the ActiveRecord configuration for the current environment.

While CE doesn't use this very often, EE will use it in a few places for
the database load balancing code. I'm adding this to CE so we don't end
up with merge conflicts in this file.
2017-03-17 17:08:10 +01:00
Tiago Botelho 53760bb836 removes redundant code from gitlab database file 2017-03-02 20:29:32 +00:00
Yorick Peterse cf521c9576
Allow setting of a custom connection pool host
This allows you to set a custom host when calling
Gitlab::Database.create_connection_pool. This is necessary for load
balancing as in this case we want to inherit all settings except for the
hostname.
2017-02-22 15:47:53 +01:00
Yorick Peterse f802ad370e Merge branch 'create-connection-pool' into 'master'
Introduce Gitlab::Database.with_connection_pool

See merge request !9192
2017-02-14 12:05:07 +00:00
Lin Jen-Shin 03f1abfcc3 Only ensure against yield so that pool should be available
Feedback:
https://gitlab.com/gitlab-org/gitlab-ce/merge_requests/9192#note_23293693
2017-02-14 13:48:13 +08:00
Lin Jen-Shin 136dc79433 Have some simple way to create connection pool 2017-02-14 00:35:25 +08:00
Yorick Peterse 581cfbae24
Don't connect in Gitlab::Database.adapter_name
We don't need to connect when requesting the name of the database
adapter. This in turn should prevent us from requesting/leaking
connections just by asking whether we're using PostgreSQL or MySQL.
2017-02-13 17:13:02 +01:00
Douwe Maan c8b63a28af Improve performance of finding last deployed environment 2017-02-06 16:12:24 -06:00
Yorick Peterse 92b2c74ce1
Refresh project authorizations using a Redis lease
When I proposed using serializable transactions I was hoping we would be
able to refresh data of individual users concurrently. Unfortunately
upon closer inspection it was revealed this was not the case. This could
result in a lot of queries failing due to serialization errors,
overloading the database in the process (given enough workers trying to
update the target table).

To work around this we're now using a Redis lease that is cancelled upon
completion. This ensures we can update the data of different users
concurrently without overloading the database.

The code will try to obtain the lease until it succeeds, waiting at
least 1 second between retries. This is necessary as we may otherwise
end up _not_ updating the data which is not an option.
2016-11-25 13:35:01 +01:00
Ahmad Sherif fd05e26618 Precalculate user's authorized projects in database
Closes #23150
2016-11-18 20:25:45 +02:00