Commit 67b7dbad authored by Dmitriy Zaporozhets's avatar Dmitriy Zaporozhets

Add package_type column to packages table

So we can distinct between Maven and NPM packages
Signed-off-by: default avatarDmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>
parent 36e58cc4
......@@ -10,7 +10,7 @@
#
# 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
enable_extension "plpgsql"
......@@ -2015,6 +2015,7 @@ ActiveRecord::Schema.define(version: 20181219145520) do
t.datetime_with_timezone "updated_at", null: false
t.string "name", null: false
t.string "version"
t.integer "package_type", limit: 2, null: false
t.index ["project_id"], name: "index_packages_packages_on_project_id", using: :btree
end
......
......@@ -12,6 +12,8 @@ class Packages::Package < ActiveRecord::Base
presence: true,
format: { with: Gitlab::Regex.package_name_regex }
enum package_type: { maven: 1 }
def self.for_projects(projects)
return none unless projects.any?
......
......@@ -8,6 +8,7 @@ module Packages
project.packages.create!(
name: params[:name],
version: params[:version],
package_type: :maven,
maven_metadatum_attributes: {
path: params[:path],
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
project
name 'my/company/app/my-app'
version '1.0-SNAPSHOT'
package_type 'maven'
factory :maven_package do
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
expect(package).to be_valid
expect(package.name).to eq(path)
expect(package.version).to eq(version)
expect(package.package_type).to eq('maven')
expect(package.maven_metadatum).to be_valid
expect(package.maven_metadatum.path).to eq(path_with_version)
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