Commit 9913c389 authored by Dmitriy Zaporozhets's avatar Dmitriy Zaporozhets

Merge branch 'dz-add-type-to-packages' into 'master'

Add package_type column to packages table

See merge request gitlab-org/gitlab-ee!8939
parents 9ce83d06 67b7dbad
...@@ -10,7 +10,7 @@ ...@@ -10,7 +10,7 @@
# #
# It's strongly recommended that you check this file into your version control system. # It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema.define(version: 20181219145520) do ActiveRecord::Schema.define(version: 20181220165848) do
# These are extensions that must be enabled in order to support this database # These are extensions that must be enabled in order to support this database
enable_extension "plpgsql" enable_extension "plpgsql"
...@@ -2015,6 +2015,7 @@ ActiveRecord::Schema.define(version: 20181219145520) do ...@@ -2015,6 +2015,7 @@ ActiveRecord::Schema.define(version: 20181219145520) do
t.datetime_with_timezone "updated_at", null: false t.datetime_with_timezone "updated_at", null: false
t.string "name", null: false t.string "name", null: false
t.string "version" t.string "version"
t.integer "package_type", limit: 2, null: false
t.index ["project_id"], name: "index_packages_packages_on_project_id", using: :btree t.index ["project_id"], name: "index_packages_packages_on_project_id", using: :btree
end end
......
...@@ -12,6 +12,8 @@ class Packages::Package < ActiveRecord::Base ...@@ -12,6 +12,8 @@ class Packages::Package < ActiveRecord::Base
presence: true, presence: true,
format: { with: Gitlab::Regex.package_name_regex } format: { with: Gitlab::Regex.package_name_regex }
enum package_type: { maven: 1 }
def self.for_projects(projects) def self.for_projects(projects)
return none unless projects.any? return none unless projects.any?
......
...@@ -8,6 +8,7 @@ module Packages ...@@ -8,6 +8,7 @@ module Packages
project.packages.create!( project.packages.create!(
name: params[:name], name: params[:name],
version: params[:version], version: params[:version],
package_type: :maven,
maven_metadatum_attributes: { maven_metadatum_attributes: {
path: params[:path], path: params[:path],
app_group: app_group, app_group: app_group,
......
# 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 AddPackageTypeToPackages < ActiveRecord::Migration[5.0]
include Gitlab::Database::MigrationHelpers
# Set this constant to true if this migration requires downtime.
DOWNTIME = false
def change
add_column :packages_packages, :package_type, :integer, limit: 2
end
end
# frozen_string_literal: true
# rubocop:disable Migration/UpdateColumnInBatches
class UpdatePackageType < ActiveRecord::Migration[5.0]
include Gitlab::Database::MigrationHelpers
disable_ddl_transaction!
# Set this constant to true if this migration requires downtime.
DOWNTIME = false
def up
update_column_in_batches(:packages_packages, :package_type, 1) do |table, query|
query.where(table[:package_type].eq(nil))
end
change_column_null(:packages_packages, :package_type, false)
end
def down
change_column_null(:packages_packages, :package_type, true)
end
end
...@@ -4,6 +4,7 @@ FactoryBot.define do ...@@ -4,6 +4,7 @@ FactoryBot.define do
project project
name 'my/company/app/my-app' name 'my/company/app/my-app'
version '1.0-SNAPSHOT' version '1.0-SNAPSHOT'
package_type 'maven'
factory :maven_package do factory :maven_package do
maven_metadatum maven_metadatum
......
# frozen_string_literal: true
require 'spec_helper'
require Rails.root.join('ee', 'db', 'post_migrate', '20181220165848_update_package_type.rb')
describe UpdatePackageType, :migration do
describe '#up' do
let(:namespace) { table(:namespaces).create(path: 'ns', name: 'Namespace') }
let(:project) { table(:projects).create(namespace_id: namespace.id, path: 'pj') }
let!(:package) { table(:packages_packages).create(name: 'foo', version: '1.0.0', project_id: project.id) }
it 'updates package_type from nil to 1' do
migrate!
expect(package.reload.package_type).to eq(1)
end
end
end
...@@ -25,6 +25,7 @@ describe Packages::CreateMavenPackageService do ...@@ -25,6 +25,7 @@ describe Packages::CreateMavenPackageService do
expect(package).to be_valid expect(package).to be_valid
expect(package.name).to eq(path) expect(package.name).to eq(path)
expect(package.version).to eq(version) expect(package.version).to eq(version)
expect(package.package_type).to eq('maven')
expect(package.maven_metadatum).to be_valid expect(package.maven_metadatum).to be_valid
expect(package.maven_metadatum.path).to eq(path_with_version) expect(package.maven_metadatum.path).to eq(path_with_version)
expect(package.maven_metadatum.app_group).to eq('my.company.app') expect(package.maven_metadatum.app_group).to eq('my.company.app')
......
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