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
52cd60dc
Commit
52cd60dc
authored
Sep 30, 2019
by
Jason Goodman
Committed by
Andreas Brandl
Sep 30, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add migration to add not null constraints to releases timestamps
Backfill null updated_at rows with created_at
parent
40cfd00d
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
88 additions
and
2 deletions
+88
-2
changelogs/unreleased/backfill-releases-updated-at.yml
changelogs/unreleased/backfill-releases-updated-at.yml
+5
-0
db/migrate/20190920194925_backfill_releases_table_updated_at_and_add_not_null_constraints_to_timestamps.rb
..._updated_at_and_add_not_null_constraints_to_timestamps.rb
+24
-0
db/schema.rb
db/schema.rb
+2
-2
spec/migrations/backfill_releases_table_updated_at_and_add_not_null_constraints_to_timestamps_spec.rb
...ted_at_and_add_not_null_constraints_to_timestamps_spec.rb
+57
-0
No files found.
changelogs/unreleased/backfill-releases-updated-at.yml
0 → 100644
View file @
52cd60dc
---
title
:
Backfill releases table updated_at column and add not
null
constraints to created_at and updated_at
merge_request
:
17400
author
:
type
:
fixed
db/migrate/20190920194925_backfill_releases_table_updated_at_and_add_not_null_constraints_to_timestamps.rb
0 → 100644
View file @
52cd60dc
# frozen_string_literal: true
class
BackfillReleasesTableUpdatedAtAndAddNotNullConstraintsToTimestamps
<
ActiveRecord
::
Migration
[
5.2
]
include
Gitlab
::
Database
::
MigrationHelpers
DOWNTIME
=
false
disable_ddl_transaction!
def
up
change_column_null
(
:releases
,
:created_at
,
false
,
Time
.
zone
.
now
)
update_column_in_batches
(
:releases
,
:updated_at
,
Arel
.
sql
(
'created_at'
))
do
|
table
,
query
|
query
.
where
(
table
[
:updated_at
].
eq
(
nil
))
end
change_column_null
(
:releases
,
:updated_at
,
false
,
Time
.
zone
.
now
)
end
def
down
change_column_null
(
:releases
,
:updated_at
,
true
)
change_column_null
(
:releases
,
:created_at
,
true
)
end
end
db/schema.rb
View file @
52cd60dc
...
...
@@ -3137,8 +3137,8 @@ ActiveRecord::Schema.define(version: 2019_09_27_074328) do
t
.
string
"tag"
t
.
text
"description"
t
.
integer
"project_id"
t
.
datetime
"created_at"
t
.
datetime
"updated_at"
t
.
datetime
"created_at"
,
null:
false
t
.
datetime
"updated_at"
,
null:
false
t
.
text
"description_html"
t
.
integer
"cached_markdown_version"
t
.
integer
"author_id"
...
...
spec/migrations/backfill_releases_table_updated_at_and_add_not_null_constraints_to_timestamps_spec.rb
0 → 100644
View file @
52cd60dc
# frozen_string_literal: true
require
'spec_helper'
require
Rails
.
root
.
join
(
'db'
,
'migrate'
,
'20190920194925_backfill_releases_table_updated_at_and_add_not_null_constraints_to_timestamps.rb'
)
describe
BackfillReleasesTableUpdatedAtAndAddNotNullConstraintsToTimestamps
,
:migration
do
let
(
:releases
)
{
table
(
:releases
)
}
let
(
:namespaces
)
{
table
(
:namespaces
)
}
let
(
:projects
)
{
table
(
:projects
)
}
subject
(
:migration
)
{
described_class
.
new
}
it
'fills null updated_at rows with the value of created_at'
do
created_at_a
=
Time
.
zone
.
parse
(
'2014-03-11T04:30:00Z'
)
created_at_b
=
Time
.
zone
.
parse
(
'2019-09-10T12:00:00Z'
)
namespace
=
namespaces
.
create
(
name:
'foo'
,
path:
'foo'
)
project
=
projects
.
create!
(
namespace_id:
namespace
.
id
)
release_a
=
releases
.
create!
(
project_id:
project
.
id
,
released_at:
Time
.
zone
.
parse
(
'2014-12-10T06:00:00Z'
),
created_at:
created_at_a
)
release_b
=
releases
.
create!
(
project_id:
project
.
id
,
released_at:
Time
.
zone
.
parse
(
'2019-09-11T06:00:00Z'
),
created_at:
created_at_b
)
release_a
.
update!
(
updated_at:
nil
)
release_b
.
update!
(
updated_at:
nil
)
disable_migrations_output
{
migrate!
}
release_a
.
reload
release_b
.
reload
expect
(
release_a
.
updated_at
).
to
eq
(
created_at_a
)
expect
(
release_b
.
updated_at
).
to
eq
(
created_at_b
)
end
it
'does not change updated_at columns with a value'
do
created_at_a
=
Time
.
zone
.
parse
(
'2014-03-11T04:30:00Z'
)
updated_at_a
=
Time
.
zone
.
parse
(
'2015-01-16T10:00:00Z'
)
created_at_b
=
Time
.
zone
.
parse
(
'2019-09-10T12:00:00Z'
)
namespace
=
namespaces
.
create
(
name:
'foo'
,
path:
'foo'
)
project
=
projects
.
create!
(
namespace_id:
namespace
.
id
)
release_a
=
releases
.
create!
(
project_id:
project
.
id
,
released_at:
Time
.
zone
.
parse
(
'2014-12-10T06:00:00Z'
),
created_at:
created_at_a
,
updated_at:
updated_at_a
)
release_b
=
releases
.
create!
(
project_id:
project
.
id
,
released_at:
Time
.
zone
.
parse
(
'2019-09-11T06:00:00Z'
),
created_at:
created_at_b
)
release_b
.
update!
(
updated_at:
nil
)
disable_migrations_output
{
migrate!
}
release_a
.
reload
release_b
.
reload
expect
(
release_a
.
updated_at
).
to
eq
(
updated_at_a
)
expect
(
release_b
.
updated_at
).
to
eq
(
created_at_b
)
end
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