summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRubén Dávila <ruben@gitlab.com>2018-11-01 18:34:15 -0500
committerRubén Dávila <ruben@gitlab.com>2018-11-01 18:34:15 -0500
commitd32a571acbebd8655991f09e63302e59ca646f68 (patch)
treecf13771ac196fedd42ee3bd6af6e8d79fa36e7e2
parent9bf59ceb691f6c3546f6b156f70767c1c4067233 (diff)
downloadgitlab-ce-rd-set-missing-fields-on-migration.tar.gz
Fixes a migration that causes error on some legacy DBsrd-set-missing-fields-on-migration
Looks like there are some legacy GitLab databases that have a NOT NULL constraint for the `created_at` and `updated` fields. This change fixes the migration by adding a default value to those columns and I think we always should have it in mind when inserting DB records through raw SQL.
-rw-r--r--db/migrate/20180413022611_create_missing_namespace_for_internal_users.rb4
1 files changed, 2 insertions, 2 deletions
diff --git a/db/migrate/20180413022611_create_missing_namespace_for_internal_users.rb b/db/migrate/20180413022611_create_missing_namespace_for_internal_users.rb
index 8fc558be733..b7b346cb10e 100644
--- a/db/migrate/20180413022611_create_missing_namespace_for_internal_users.rb
+++ b/db/migrate/20180413022611_create_missing_namespace_for_internal_users.rb
@@ -45,7 +45,7 @@ class CreateMissingNamespaceForInternalUsers < ActiveRecord::Migration
connection.exec_query(query).present?
end
- insert_query = "INSERT INTO namespaces(owner_id, path, name) VALUES(#{user_id}, '#{path}', '#{path}')"
+ insert_query = "INSERT INTO namespaces(owner_id, path, name, created_at, updated_at) VALUES(#{user_id}, '#{path}', '#{path}', NOW(), NOW())"
namespace_id = connection.insert_sql(insert_query)
create_route(namespace_id)
@@ -57,7 +57,7 @@ class CreateMissingNamespaceForInternalUsers < ActiveRecord::Migration
row = connection.exec_query("SELECT id, path FROM namespaces WHERE id=#{namespace_id}").first
id, path = row.values_at('id', 'path')
- execute("INSERT INTO routes(source_id, source_type, path, name) VALUES(#{id}, 'Namespace', '#{path}', '#{path}')")
+ execute("INSERT INTO routes(source_id, source_type, path, name, created_at, updated_at) VALUES(#{id}, 'Namespace', '#{path}', '#{path}', NOW(), NOW())")
end
def set_notification_email(user_id)