Commit cbe6403e authored by Dmitriy Zaporozhets's avatar Dmitriy Zaporozhets

Improve database schema for packages feature [ci skip]

Signed-off-by: default avatarDmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>
parent 61e32695
......@@ -11,7 +11,7 @@
#
# It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema.define(version: 20180807153545) do
ActiveRecord::Schema.define(version: 20180810155213) do
# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"
......@@ -1922,38 +1922,40 @@ ActiveRecord::Schema.define(version: 20180807153545) do
end
create_table "packages_maven_metadata", force: :cascade do |t|
t.datetime_with_timezone "created_at", null: false
t.datetime_with_timezone "updated_at", null: false
t.integer "package_id", null: false
t.string "path", null: false
t.string "app_group", null: false
t.string "app_name", null: false
t.string "app_version"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
end
add_index "packages_maven_metadata", ["package_id"], name: "index_packages_maven_metadata_on_package_id", using: :btree
add_index "packages_maven_metadata", ["path"], name: "index_packages_maven_metadata_on_path", using: :btree
create_table "packages_package_files", force: :cascade do |t|
t.datetime_with_timezone "created_at", null: false
t.datetime_with_timezone "updated_at", null: false
t.integer "package_id", null: false
t.string "file"
t.string "file_name", null: false
t.integer "file_type"
t.integer "file_store"
t.integer "size"
t.binary "file_md5"
t.binary "file_sha1"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.string "file"
t.string "file_name", null: false
end
add_index "packages_package_files", ["package_id", "file_name"], name: "index_packages_package_files_on_package_id_and_file_name", using: :btree
add_index "packages_package_files", ["package_id"], name: "index_packages_package_files_on_package_id", using: :btree
create_table "packages_packages", force: :cascade do |t|
t.datetime_with_timezone "created_at", null: false
t.datetime_with_timezone "updated_at", null: false
t.integer "project_id", null: false
t.string "name", null: false
t.string "version"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
end
add_index "packages_packages", ["project_id"], name: "index_packages_packages_on_project_id", using: :btree
......@@ -3119,6 +3121,8 @@ ActiveRecord::Schema.define(version: 20180807153545) do
add_foreign_key "notes", "projects", name: "fk_99e097b079", on_delete: :cascade
add_foreign_key "notification_settings", "users", name: "fk_0c95e91db7", on_delete: :cascade
add_foreign_key "oauth_openid_requests", "oauth_access_grants", column: "access_grant_id", name: "fk_oauth_openid_requests_oauth_access_grants_access_grant_id"
add_foreign_key "packages_maven_metadata", "packages_packages", column: "package_id", name: "fk_be88aed360", on_delete: :cascade
add_foreign_key "packages_package_files", "packages_packages", column: "package_id", name: "fk_86f0f182f8", on_delete: :cascade
add_foreign_key "pages_domains", "projects", name: "fk_ea2f6dfc6f", on_delete: :cascade
add_foreign_key "path_locks", "projects", name: "fk_5265c98f24", on_delete: :cascade
add_foreign_key "path_locks", "users"
......
# frozen_string_literal: true
class CreatePackagesPackages < ActiveRecord::Migration
include Gitlab::Database::MigrationHelpers
DOWNTIME = false
disable_ddl_transaction!
def change
create_table :packages_packages do |t|
t.timestamps_with_timezone null: false
t.references :project, index: true, foreign_key: { on_delete: :cascade }, null: false
t.string :name, null: false
t.string :version
t.timestamps_with_timezone null: false
end
end
end
......@@ -8,16 +8,18 @@ class CreatePackagesPackageFiles < ActiveRecord::Migration
def up
create_table :packages_package_files do |t|
t.timestamps_with_timezone null: false
t.references :package, index: true, null: false
t.string :file
t.string :file_name, null: false
t.integer :file_type
t.integer :file_store
t.integer :size
t.binary :file_md5
t.binary :file_sha1
t.timestamps_with_timezone null: false
t.string :file
t.string :file_name, null: false
end
add_concurrent_foreign_key :packages_package_files, :packages_packages,
......
......@@ -8,13 +8,13 @@ class CreatePackagesMavenMetadata < ActiveRecord::Migration
def up
create_table :packages_maven_metadata do |t|
t.timestamps_with_timezone null: false
t.references :package, index: true, null: false
t.string :path, null: false
t.string :app_group, null: false
t.string :app_name, null: false
t.string :app_version
t.timestamps_with_timezone null: false
end
add_concurrent_foreign_key :packages_maven_metadata, :packages_packages,
......
class AddMoreIndicesToPackages < ActiveRecord::Migration
include Gitlab::Database::MigrationHelpers
DOWNTIME = false
disable_ddl_transaction!
def up
add_concurrent_index :packages_package_files, [:package_id, :file_name]
add_concurrent_index :packages_maven_metadata, :path
end
def down
remove_concurrent_index :packages_package_files, [:package_id, :file_name]
remove_concurrent_index :packages_maven_metadata, :path
end
end
......@@ -26,11 +26,11 @@ module API
forbidden! unless user_project.feature_available?(:packages)
end
def authorize_can_read!
def authorize_download_package!
authorize!(:read_package, user_project)
end
def authorize_can_admin!
def authorize_create_package!
authorize!(:admin_package, user_project)
end
......@@ -68,7 +68,7 @@ module API
requires :file_name, type: String, desc: 'Package file name'
end
get ':id/packages/maven/*path/:file_name', requirements: MAVEN_ENDPOINT_REQUIREMENTS do
authorize_can_read!
authorize_download_package!
file_name, format = extract_format(params[:file_name])
......@@ -96,7 +96,7 @@ module API
requires :file_name, type: String, desc: 'Package file name'
end
put ':id/packages/maven/*path/:file_name/authorize', requirements: MAVEN_ENDPOINT_REQUIREMENTS do
authorize_can_admin!
authorize_create_package!
require_gitlab_workhorse!
Gitlab::Workhorse.verify_api_request!(headers)
......@@ -121,7 +121,7 @@ module API
optional 'file.sha256', type: String, desc: %q(sha256 checksum of the file (generated by Workhorse))
end
put ':id/packages/maven/*path/:file_name', requirements: MAVEN_ENDPOINT_REQUIREMENTS do
authorize_can_admin!
authorize_create_package!
require_gitlab_workhorse!
......
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