Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
heptapod
heptapod
Commits
81da3eeaf712
Commit
bc00806a
authored
Jun 13, 2017
by
blackst0ne
Browse files
Add database helpers 'add_timestamps_with_timezone' and 'timestamps_with_timezone'
parent
c9ed0fef0db9
Changes
49
Hide whitespace changes
Inline
Side-by-side
changelogs/unreleased/32054-rails-should-use-timestamptz-database-type-for-postgresql.yml
0 → 100644
View file @
81da3eea
---
title
:
Add database helpers 'add_timestamps_with_timezone' and 'timestamps_with_timezone'
merge_request
:
11229
author
:
@
blackst0ne
config/initializers/active_record_data_types.rb
0 → 100644
View file @
81da3eea
# ActiveRecord custom data type for storing datetimes with timezone information.
# See https://gitlab.com/gitlab-org/gitlab-ce/merge_requests/11229
if
Gitlab
::
Database
.
postgresql?
require
'active_record/connection_adapters/postgresql_adapter'
module
ActiveRecord
module
ConnectionAdapters
class
PostgreSQLAdapter
NATIVE_DATABASE_TYPES
.
merge!
(
datetime_with_timezone:
{
name:
'timestamptz'
})
end
end
end
elsif
Gitlab
::
Database
.
mysql?
require
'active_record/connection_adapters/mysql2_adapter'
module
ActiveRecord
module
ConnectionAdapters
class
AbstractMysqlAdapter
NATIVE_DATABASE_TYPES
.
merge!
(
datetime_with_timezone:
{
name:
'timestamp'
})
end
end
end
end
config/initializers/active_record_table_definition.rb
0 → 100644
View file @
81da3eea
# ActiveRecord custom method definitions with timezone information.
# See https://gitlab.com/gitlab-org/gitlab-ce/merge_requests/11229
require
'active_record/connection_adapters/abstract/schema_definitions'
# Appends columns `created_at` and `updated_at` to a table.
#
# It is used in table creation like:
# create_table 'users' do |t|
# t.timestamps_with_timezone
# end
module
ActiveRecord
module
ConnectionAdapters
class
TableDefinition
def
timestamps_with_timezone
(
**
options
)
options
[
:null
]
=
false
if
options
[
:null
].
nil?
[
:created_at
,
:updated_at
].
each
do
|
column_name
|
column
(
column_name
,
:datetime_with_timezone
,
options
)
end
end
end
end
end
db/migrate/20160314114439_add_requested_at_to_members.rb
View file @
81da3eea
# rubocop:disable Migration/Datetime
class
AddRequestedAtToMembers
<
ActiveRecord
::
Migration
def
change
add_column
:members
,
:requested_at
,
:datetime
...
...
db/migrate/20160415062917_create_personal_access_tokens.rb
View file @
81da3eea
# rubocop:disable Migration/Datetime
# rubocop:disable Migration/Timestamps
class
CreatePersonalAccessTokens
<
ActiveRecord
::
Migration
def
change
create_table
:personal_access_tokens
do
|
t
|
...
...
db/migrate/20160610204157_add_deployments.rb
View file @
81da3eea
# See http://doc.gitlab.com/ce/development/migration_style_guide.html
# for more information on how to write migrations for GitLab.
# rubocop:disable Migration/Datetime
class
AddDeployments
<
ActiveRecord
::
Migration
include
Gitlab
::
Database
::
MigrationHelpers
...
...
db/migrate/20160610204158_add_environments.rb
View file @
81da3eea
# See http://doc.gitlab.com/ce/development/migration_style_guide.html
# for more information on how to write migrations for GitLab.
# rubocop:disable Migration/Datetime
class
AddEnvironments
<
ActiveRecord
::
Migration
include
Gitlab
::
Database
::
MigrationHelpers
...
...
db/migrate/20160705054938_add_protected_branches_push_access.rb
View file @
81da3eea
# See http://doc.gitlab.com/ce/development/migration_style_guide.html
# for more information on how to write migrations for GitLab.
# rubocop:disable Migration/Timestamps
class
AddProtectedBranchesPushAccess
<
ActiveRecord
::
Migration
DOWNTIME
=
false
...
...
db/migrate/20160705054952_add_protected_branches_merge_access.rb
View file @
81da3eea
# See http://doc.gitlab.com/ce/development/migration_style_guide.html
# for more information on how to write migrations for GitLab.
# rubocop:disable Migration/Timestamps
class
AddProtectedBranchesMergeAccess
<
ActiveRecord
::
Migration
DOWNTIME
=
false
...
...
db/migrate/20160724205507_add_resolved_to_notes.rb
View file @
81da3eea
# rubocop:disable Migration/Datetime
class
AddResolvedToNotes
<
ActiveRecord
::
Migration
include
Gitlab
::
Database
::
MigrationHelpers
...
...
db/migrate/20160727163552_create_user_agent_details.rb
View file @
81da3eea
# rubocop:disable Migration/Timestamps
class
CreateUserAgentDetails
<
ActiveRecord
::
Migration
include
Gitlab
::
Database
::
MigrationHelpers
...
...
db/migrate/20160727191041_create_boards.rb
View file @
81da3eea
# rubocop:disable Migration/Timestamps
class
CreateBoards
<
ActiveRecord
::
Migration
include
Gitlab
::
Database
::
MigrationHelpers
...
...
db/migrate/20160727193336_create_lists.rb
View file @
81da3eea
# rubocop:disable Migration/Timestamps
class
CreateLists
<
ActiveRecord
::
Migration
include
Gitlab
::
Database
::
MigrationHelpers
...
...
db/migrate/20160805041956_add_deleted_at_to_namespaces.rb
View file @
81da3eea
# rubocop:disable Migration/Datetime
# rubocop:disable RemoveIndex
class
AddDeletedAtToNamespaces
<
ActiveRecord
::
Migration
include
Gitlab
::
Database
::
MigrationHelpers
...
...
db/migrate/20160824124900_add_table_issue_metrics.rb
View file @
81da3eea
# See http://doc.gitlab.com/ce/development/migration_style_guide.html
# for more information on how to write migrations for GitLab.
# rubocop:disable Migration/Datetime
# rubocop:disable Migration/Timestamps
class
AddTableIssueMetrics
<
ActiveRecord
::
Migration
include
Gitlab
::
Database
::
MigrationHelpers
...
...
db/migrate/20160825052008_add_table_merge_request_metrics.rb
View file @
81da3eea
# See http://doc.gitlab.com/ce/development/migration_style_guide.html
# for more information on how to write migrations for GitLab.
# rubocop:disable Migration/Datetime
# rubocop:disable Migration/Timestamps
class
AddTableMergeRequestMetrics
<
ActiveRecord
::
Migration
include
Gitlab
::
Database
::
MigrationHelpers
...
...
db/migrate/20160831214002_create_project_features.rb
View file @
81da3eea
# rubocop:disable Migration/Timestamps
class
CreateProjectFeatures
<
ActiveRecord
::
Migration
DOWNTIME
=
false
...
...
db/migrate/20160915042921_create_merge_requests_closing_issues.rb
View file @
81da3eea
# See http://doc.gitlab.com/ce/development/migration_style_guide.html
# for more information on how to write migrations for GitLab.
# rubocop:disable Migration/Timestamps
class
CreateMergeRequestsClosingIssues
<
ActiveRecord
::
Migration
include
Gitlab
::
Database
::
MigrationHelpers
...
...
db/migrate/20161014173530_create_label_priorities.rb
View file @
81da3eea
# rubocop:disable Migration/Timestamps
class
CreateLabelPriorities
<
ActiveRecord
::
Migration
include
Gitlab
::
Database
::
MigrationHelpers
...
...
db/migrate/20161113184239_create_user_chat_names_table.rb
View file @
81da3eea
# rubocop:disable Migration/Datetime
# rubocop:disable Migration/Timestamps
class
CreateUserChatNamesTable
<
ActiveRecord
::
Migration
include
Gitlab
::
Database
::
MigrationHelpers
...
...
Prev
1
2
3
Next
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