Skip to content

Commit

Permalink
[webui] Add migrations for Kiwi Packages
Browse files Browse the repository at this point in the history
We got the needed attributes found in:
  - https://doc.opensuse.org/projects/kiwi/schema-doc/
  - https://doc.opensuse.org/projects/kiwi/doc/#sec.description.packages

We also introduced the needed validations in the models.

Pair-programmed by @DavidKang and @Ana06.
  • Loading branch information
DavidKang authored and Ana06 committed Jul 18, 2017
1 parent 03c0dd9 commit a1e0e1c
Show file tree
Hide file tree
Showing 8 changed files with 118 additions and 2 deletions.
3 changes: 2 additions & 1 deletion src/api/app/models/kiwi/image.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,9 @@ class Kiwi::Image < ApplicationRecord
#### Attributes

#### Associations macros (Belongs to, Has one, Has many)
has_one :package, foreign_key: 'kiwi_image_id', dependent: :nullify, inverse_of: :kiwi_image
has_one :package, foreign_key: 'kiwi_image_id', class_name: '::Package', dependent: :nullify, inverse_of: :kiwi_image
has_many :repositories, -> { order(order: :asc) }, dependent: :destroy, index_errors: true
has_many :package_groups, dependent: :destroy, index_errors: true

#### Callbacks macros: before_save, after_save, etc.

Expand Down
24 changes: 24 additions & 0 deletions src/api/app/models/kiwi/package.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
class Kiwi::Package < ApplicationRecord
belongs_to :package_group

validates :name, presence: true
end

# == Schema Information
#
# Table name: kiwi_packages
#
# id :integer not null, primary key
# name :string(255) not null
# arch :string(255)
# replaces :string(255)
# bootinclude :boolean
# bootdelete :boolean
# package_group_id :integer indexed
# created_at :datetime not null
# updated_at :datetime not null
#
# Indexes
#
# index_kiwi_packages_on_package_group_id (package_group_id)
#
27 changes: 27 additions & 0 deletions src/api/app/models/kiwi/package_group.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
class Kiwi::PackageGroup < ApplicationRecord
has_many :packages
belongs_to :image

# we need to add a prefix, to avoid generating class methods that already
# exist in Active Record, such as "delete"
enum kiwi_type: %i[bootstrap delete docker image iso lxc oem pxe split testsuite vmx], _prefix: :type

validates :kiwi_type, presence: true, inclusion: { in: kiwi_types.keys }
end

# == Schema Information
#
# Table name: kiwi_package_groups
#
# id :integer not null, primary key
# kiwi_type :integer not null
# profiles :string(255)
# pattern_type :string(255)
# image_id :integer indexed
# created_at :datetime not null
# updated_at :datetime not null
#
# Indexes
#
# index_kiwi_package_groups_on_image_id (image_id)
#
12 changes: 12 additions & 0 deletions src/api/db/migrate/20170710133627_create_kiwi_package_groups.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
class CreateKiwiPackageGroups < ActiveRecord::Migration[5.1]
def change
create_table :kiwi_package_groups do |t|
t.integer :kiwi_type, null: false
t.string :profiles
t.string :pattern_type
t.belongs_to :image, index: true

t.timestamps
end
end
end
14 changes: 14 additions & 0 deletions src/api/db/migrate/20170710134059_create_kiwi_packages.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
class CreateKiwiPackages < ActiveRecord::Migration[5.1]
def change
create_table :kiwi_packages do |t|
t.string :name, null: false
t.string :arch
t.string :replaces
t.boolean :bootinclude
t.boolean :bootdelete
t.belongs_to :package_group, index: true

t.timestamps
end
end
end
30 changes: 29 additions & 1 deletion src/api/db/structure.sql
Original file line number Diff line number Diff line change
Expand Up @@ -628,6 +628,32 @@ CREATE TABLE `kiwi_images` (
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

CREATE TABLE `kiwi_package_groups` (
`id` bigint(20) NOT NULL AUTO_INCREMENT,
`kiwi_type` int(11) NOT NULL,
`profiles` varchar(255) DEFAULT NULL,
`pattern_type` varchar(255) DEFAULT NULL,
`image_id` bigint(20) DEFAULT NULL,
`created_at` datetime NOT NULL,
`updated_at` datetime NOT NULL,
PRIMARY KEY (`id`),
KEY `index_kiwi_package_groups_on_image_id` (`image_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

CREATE TABLE `kiwi_packages` (
`id` bigint(20) NOT NULL AUTO_INCREMENT,
`name` varchar(255) NOT NULL,
`arch` varchar(255) DEFAULT NULL,
`replaces` varchar(255) DEFAULT NULL,
`bootinclude` tinyint(1) DEFAULT NULL,
`bootdelete` tinyint(1) DEFAULT NULL,
`package_group_id` bigint(20) DEFAULT NULL,
`created_at` datetime NOT NULL,
`updated_at` datetime NOT NULL,
PRIMARY KEY (`id`),
KEY `index_kiwi_packages_on_package_group_id` (`package_group_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

CREATE TABLE `kiwi_repositories` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`image_id` int(11) DEFAULT NULL,
Expand Down Expand Up @@ -1248,6 +1274,8 @@ INSERT INTO `schema_migrations` (version) VALUES
('20170630144825'),
('20170704125123'),
('20170704133728'),
('20170704212201');
('20170704212201'),
('20170710133627'),
('20170710134059');


5 changes: 5 additions & 0 deletions src/api/spec/models/kiwi/package_group_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
require 'rails_helper'

RSpec.describe Kiwi::PackageGroup, type: :model do
pending "add some examples to (or delete) #{__FILE__}"
end
5 changes: 5 additions & 0 deletions src/api/spec/models/kiwi/package_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
require 'rails_helper'

RSpec.describe Kiwi::Package, type: :model do
pending "add some examples to (or delete) #{__FILE__}"
end

0 comments on commit a1e0e1c

Please sign in to comment.