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
149e7056
Commit
149e7056
authored
Sep 08, 2017
by
Douglas Barbosa Alexandre
Committed by
Nick Thomas
Sep 08, 2017
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add a unique index on project_id to the Geo project_registry table
parent
c83f86d2
Changes
6
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
58 additions
and
12 deletions
+58
-12
app/models/geo/project_registry.rb
app/models/geo/project_registry.rb
+1
-1
changelogs/unreleased-ee/3354-add-unique-index-on-project-id-to-geo-project-registry-table.yml
...que-index-on-project-id-to-geo-project-registry-table.yml
+5
-0
db/geo/migrate/20170906174622_remove_duplicates_from_project_registry.rb
...20170906174622_remove_duplicates_from_project_registry.rb
+23
-0
db/geo/migrate/20170906182752_add_unique_index_to_project_id_on_project_registry.rb
...752_add_unique_index_to_project_id_on_project_registry.rb
+17
-0
db/geo/schema.rb
db/geo/schema.rb
+2
-2
spec/models/geo/project_registry_spec.rb
spec/models/geo/project_registry_spec.rb
+10
-9
No files found.
app/models/geo/project_registry.rb
View file @
149e7056
class
Geo::ProjectRegistry
<
Geo
::
BaseRegistry
belongs_to
:project
validates
:project
,
presence:
true
validates
:project
,
presence:
true
,
uniqueness:
true
scope
:dirty
,
->
{
where
(
arel_table
[
:resync_repository
].
eq
(
true
).
or
(
arel_table
[
:resync_wiki
].
eq
(
true
)))
}
...
...
changelogs/unreleased-ee/3354-add-unique-index-on-project-id-to-geo-project-registry-table.yml
0 → 100644
View file @
149e7056
---
title
:
Geo - Add a unique index on project_id to the Geo project_registry table
merge_request
:
2850
author
:
type
:
fixed
db/geo/migrate/20170906174622_remove_duplicates_from_project_registry.rb
0 → 100644
View file @
149e7056
class
RemoveDuplicatesFromProjectRegistry
<
ActiveRecord
::
Migration
include
Gitlab
::
Database
::
MigrationHelpers
DOWNTIME
=
false
def
up
execute
<<-
SQL
WITH good_rows AS (
SELECT project_id, MAX(id) as max_id
FROM project_registry
GROUP BY project_id
HAVING COUNT(*) > 1
)
DELETE FROM project_registry duplicated_rows
USING good_rows
WHERE good_rows.project_id = duplicated_rows.project_id
AND good_rows.max_id <> duplicated_rows.id;
SQL
end
def
down
end
end
db/geo/migrate/20170906182752_add_unique_index_to_project_id_on_project_registry.rb
0 → 100644
View file @
149e7056
class
AddUniqueIndexToProjectIdOnProjectRegistry
<
ActiveRecord
::
Migration
include
Gitlab
::
Database
::
MigrationHelpers
DOWNTIME
=
false
disable_ddl_transaction!
def
up
remove_concurrent_index
:project_registry
,
:project_id
if
index_exists?
:project_registry
,
:project_id
add_concurrent_index
:project_registry
,
:project_id
,
unique:
true
end
def
down
remove_concurrent_index
:project_registry
,
:project_id
if
index_exists?
:project_registry
,
:project_id
add_concurrent_index
:project_registry
,
:project_id
end
end
db/geo/schema.rb
View file @
149e7056
...
...
@@ -11,7 +11,7 @@
#
# It's strongly recommended that you check this file into your version control system.
ActiveRecord
::
Schema
.
define
(
version:
20170
627195211
)
do
ActiveRecord
::
Schema
.
define
(
version:
20170
906182752
)
do
# These are extensions that must be enabled in order to support this database
enable_extension
"plpgsql"
...
...
@@ -43,7 +43,7 @@ ActiveRecord::Schema.define(version: 20170627195211) do
add_index
"project_registry"
,
[
"last_repository_successful_sync_at"
],
name:
"index_project_registry_on_last_repository_successful_sync_at"
,
using: :btree
add_index
"project_registry"
,
[
"last_repository_synced_at"
],
name:
"index_project_registry_on_last_repository_synced_at"
,
using: :btree
add_index
"project_registry"
,
[
"project_id"
],
name:
"index_project_registry_on_project_id"
,
using: :btree
add_index
"project_registry"
,
[
"project_id"
],
name:
"index_project_registry_on_project_id"
,
u
nique:
true
,
u
sing: :btree
add_index
"project_registry"
,
[
"resync_repository"
],
name:
"index_project_registry_on_resync_repository"
,
using: :btree
add_index
"project_registry"
,
[
"resync_wiki"
],
name:
"index_project_registry_on_resync_wiki"
,
using: :btree
...
...
spec/models/geo/project_registry_spec.rb
View file @
149e7056
require
'spec_helper'
describe
Geo
::
ProjectRegistry
do
subject
{
create
(
:geo_project_registry
)
}
describe
'relationships'
do
it
{
is_expected
.
to
belong_to
(
:project
)
}
end
describe
'validations'
do
it
{
is_expected
.
to
validate_presence_of
(
:project
)
}
it
{
is_expected
.
to
validate_uniqueness_of
(
:project
)
}
end
describe
'.failed'
do
it
'returns projects where last attempt to sync failed'
do
project
=
create
(
:project
)
create
(
:geo_project_registry
,
:synced
,
project:
project
)
create
(
:geo_project_registry
,
:synced
,
:dirty
,
project:
project
)
repository_sync_failed
=
create
(
:geo_project_registry
,
:repository_sync_failed
,
project:
project
)
wiki_sync_failed
=
create
(
:geo_project_registry
,
:wiki_sync_failed
,
project:
project
)
create
(
:geo_project_registry
,
:synced
)
create
(
:geo_project_registry
,
:synced
,
:dirty
)
repository_sync_failed
=
create
(
:geo_project_registry
,
:repository_sync_failed
)
wiki_sync_failed
=
create
(
:geo_project_registry
,
:wiki_sync_failed
)
expect
(
described_class
.
failed
).
to
match_array
([
repository_sync_failed
,
wiki_sync_failed
])
end
...
...
@@ -23,10 +25,9 @@ describe Geo::ProjectRegistry do
describe
'.synced'
do
it
'returns synced projects'
do
project
=
create
(
:project
)
create
(
:geo_project_registry
,
:synced
,
:dirty
,
project:
project
)
create
(
:geo_project_registry
,
:sync_failed
,
project:
project
)
synced_project
=
create
(
:geo_project_registry
,
:synced
,
project:
project
)
create
(
:geo_project_registry
,
:synced
,
:dirty
)
create
(
:geo_project_registry
,
:sync_failed
)
synced_project
=
create
(
:geo_project_registry
,
:synced
)
expect
(
described_class
.
synced
).
to
match_array
([
synced_project
])
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