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
24a11c95
Commit
24a11c95
authored
Feb 04, 2018
by
Andreas Brandl
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Set todos#author_id to NOT NULL.
parent
d07addbf
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
31 additions
and
3 deletions
+31
-3
app/models/todo.rb
app/models/todo.rb
+1
-0
changelogs/unreleased/32282-add-foreign-keys-to-todos.yml
changelogs/unreleased/32282-add-foreign-keys-to-todos.yml
+1
-1
db/post_migrate/20180204200836_change_author_id_to_not_null_in_todos.rb
...e/20180204200836_change_author_id_to_not_null_in_todos.rb
+26
-0
db/schema.rb
db/schema.rb
+2
-2
spec/models/todo_spec.rb
spec/models/todo_spec.rb
+1
-0
No files found.
app/models/todo.rb
View file @
24a11c95
...
...
@@ -28,6 +28,7 @@ class Todo < ActiveRecord::Base
delegate
:name
,
:email
,
to: :author
,
prefix:
true
,
allow_nil:
true
validates
:action
,
:project
,
:target_type
,
:user
,
presence:
true
validates
:author
,
presence:
true
validates
:target_id
,
presence:
true
,
unless: :for_commit?
validates
:commit_id
,
presence:
true
,
if: :for_commit?
...
...
changelogs/unreleased/32282-add-foreign-keys-to-todos.yml
View file @
24a11c95
---
title
:
Add foreign key constraints to todos table.
title
:
Add foreign key
and NOT NULL
constraints to todos table.
merge_request
:
16849
author
:
type
:
other
db/post_migrate/20180204200836_change_author_id_to_not_null_in_todos.rb
0 → 100644
View file @
24a11c95
class
ChangeAuthorIdToNotNullInTodos
<
ActiveRecord
::
Migration
include
Gitlab
::
Database
::
MigrationHelpers
class
Todo
<
ActiveRecord
::
Base
self
.
table_name
=
'todos'
include
EachBatch
end
BATCH_SIZE
=
1000
DOWNTIME
=
false
disable_ddl_transaction!
def
up
Todo
.
where
(
author_id:
nil
).
each_batch
(
of:
BATCH_SIZE
)
do
|
batch
|
batch
.
delete_all
end
change_column_null
:todos
,
:author_id
,
false
end
def
down
change_column_null
:todos
,
:author_id
,
true
end
end
db/schema.rb
View file @
24a11c95
...
...
@@ -11,7 +11,7 @@
#
# It's strongly recommended that you check this file into your version control system.
ActiveRecord
::
Schema
.
define
(
version:
2018020
211110
6
)
do
ActiveRecord
::
Schema
.
define
(
version:
2018020
420083
6
)
do
# These are extensions that must be enabled in order to support this database
enable_extension
"plpgsql"
...
...
@@ -1707,7 +1707,7 @@ ActiveRecord::Schema.define(version: 20180202111106) do
t
.
integer
"project_id"
,
null:
false
t
.
integer
"target_id"
t
.
string
"target_type"
,
null:
false
t
.
integer
"author_id"
t
.
integer
"author_id"
,
null:
false
t
.
integer
"action"
,
null:
false
t
.
string
"state"
,
null:
false
t
.
datetime
"created_at"
...
...
spec/models/todo_spec.rb
View file @
24a11c95
...
...
@@ -20,6 +20,7 @@ describe Todo do
it
{
is_expected
.
to
validate_presence_of
(
:action
)
}
it
{
is_expected
.
to
validate_presence_of
(
:target_type
)
}
it
{
is_expected
.
to
validate_presence_of
(
:user
)
}
it
{
is_expected
.
to
validate_presence_of
(
:author
)
}
context
'for commits'
do
subject
{
described_class
.
new
(
target_type:
'Commit'
)
}
...
...
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