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
9137b716
Commit
9137b716
authored
May 12, 2021
by
Thong Kuah
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Prevent future timestamps in migration files
parent
d02bf43a
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
25 additions
and
0 deletions
+25
-0
.gitlab/ci/rails.gitlab-ci.yml
.gitlab/ci/rails.gitlab-ci.yml
+1
-0
scripts/validate_migration_timestamps
scripts/validate_migration_timestamps
+24
-0
No files found.
.gitlab/ci/rails.gitlab-ci.yml
View file @
9137b716
...
...
@@ -340,6 +340,7 @@ db:check-schema:
-
.rails:rules:ee-mr-and-default-branch-only
script
:
-
source scripts/schema_changed.sh
-
scripts/validate_migration_timestamps
db:check-migrations:
extends
:
...
...
scripts/validate_migration_timestamps
0 → 100755
View file @
9137b716
#!/usr/bin/env ruby
# frozen_string_literal: true
require
'time'
MIGRATION_DIRS
=
%w[db/migrate db/post_migrate]
.
freeze
VERSION_DIGITS
=
14
MIGRATION_TIMESTAMP_REGEX
=
/\A(?<version>\d{
#{
VERSION_DIGITS
}
})_/
.
freeze
maximum_timestamp
=
Time
.
now
.
utc
.
strftime
(
'%Y%m%d%H%M%S'
).
to_i
MIGRATION_DIRS
.
each
do
|
migration_dir
|
Dir
[
File
.
join
(
migration_dir
,
'*.rb'
)].
each
do
|
filename
|
file_basename
=
File
.
basename
(
filename
)
version_match
=
MIGRATION_TIMESTAMP_REGEX
.
match
(
file_basename
)
raise
"
#{
filename
}
has an invalid migration version"
if
version_match
.
nil?
migration_timestamp
=
version_match
[
'version'
].
to_i
raise
"
#{
filename
}
has a future timestamp"
if
migration_timestamp
>
maximum_timestamp
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