Commit 0d2550b0 authored by Andreas Brandl's avatar Andreas Brandl

Merge branch 'update-software-license-policy' into 'master'

Update timestamp values for software license policies

See merge request gitlab-org/gitlab!23197
parents b9cfc2f6 93e72d5d
# frozen_string_literal: true
# See http://doc.gitlab.com/ce/development/migration_style_guide.html
# for more information on how to write migrations for GitLab.
class UpdateTimestampSoftwarelicensespolicy < ActiveRecord::Migration[5.2]
include Gitlab::Database::MigrationHelpers
DOWNTIME = false
disable_ddl_transaction!
def up
time = Time.zone.now
update_column_in_batches(:software_license_policies, :created_at, time) do |table, query|
query.where(table[:created_at].eq(nil))
end
update_column_in_batches(:software_license_policies, :updated_at, time) do |table, query|
query.where(table[:updated_at].eq(nil))
end
end
def down
# no-op
end
end
# frozen_string_literal: true
# See http://doc.gitlab.com/ce/development/migration_style_guide.html
# for more information on how to write migrations for GitLab.
class UpdateTimestampSoftwarelicensespolicyNotNull < ActiveRecord::Migration[5.2]
include Gitlab::Database::MigrationHelpers
DOWNTIME = false
def change
change_column_null(:software_license_policies, :created_at, false)
change_column_null(:software_license_policies, :updated_at, false)
end
end
......@@ -10,7 +10,7 @@
#
# It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema.define(version: 2020_01_17_112554) do
ActiveRecord::Schema.define(version: 2020_01_21_132641) do
# These are extensions that must be enabled in order to support this database
enable_extension "pg_trgm"
......@@ -3857,8 +3857,8 @@ ActiveRecord::Schema.define(version: 2020_01_17_112554) do
t.integer "project_id", null: false
t.integer "software_license_id", null: false
t.integer "classification", default: 0, null: false
t.datetime_with_timezone "created_at"
t.datetime_with_timezone "updated_at"
t.datetime_with_timezone "created_at", null: false
t.datetime_with_timezone "updated_at", null: false
t.index ["project_id", "software_license_id"], name: "index_software_license_policies_unique_per_project", unique: true
t.index ["software_license_id"], name: "index_software_license_policies_on_software_license_id"
end
......
# frozen_string_literal: true
require 'spec_helper'
require Rails.root.join('db', 'migrate', '20200116175538_update_timestamp_softwarelicensespolicy.rb')
describe UpdateTimestampSoftwarelicensespolicy, :migration do
let(:software_licenses_policy) { table(:software_license_policies) }
let(:projects) { table(:projects) }
let(:licenses) { table(:software_licenses) }
before do
projects.create!(name: 'gitlab', path: 'gitlab-org/gitlab-ce', namespace_id: 1)
licenses.create!(name: 'MIT')
software_licenses_policy.create!(project_id: projects.first.id, software_license_id: licenses.first.id, created_at: nil, updated_at: nil)
end
it 'creates timestamps' do
migrate!
expect(software_licenses_policy.first.created_at).to be_present
expect(software_licenses_policy.first.updated_at).to be_present
end
end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment