Skip to content

Commit

Permalink
Introduces initial data model
Browse files Browse the repository at this point in the history
A Distribution has many Repository
A Repository has many Packages
A Package has many Versions
A Package has many Categories

ActiveJobs are in the database too.
  • Loading branch information
hennevogel committed Nov 8, 2023
1 parent 801348c commit 64aed3f
Show file tree
Hide file tree
Showing 9 changed files with 299 additions and 0 deletions.
13 changes: 13 additions & 0 deletions db/migrate/20220629143750_create_distributions.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
class CreateDistributions < ActiveRecord::Migration[7.0]
def change
create_table :distributions do |t|

t.string :vendor
t.string :name
t.string :version
t.string :url
t.string :obs_repo_names
t.timestamps
end
end
end
12 changes: 12 additions & 0 deletions db/migrate/20220630093129_create_repositories.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
class CreateRepositories < ActiveRecord::Migration[7.0]
def change
create_table :repositories do |t|
t.string :url
t.boolean :updateinfo, default: false
t.string :revision
t.references :distribution

t.timestamps
end
end
end
18 changes: 18 additions & 0 deletions db/migrate/20220630093339_create_packages.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
class CreatePackages < ActiveRecord::Migration[7.0]
def change
create_table :packages do |t|
t.string :name
t.string :release
t.string :architectures
t.string :license
t.string :url
t.string :title
t.string :summary
t.text :description
t.boolean :appstream, default: false
t.references :repository

t.timestamps
end
end
end
38 changes: 38 additions & 0 deletions db/migrate/20220701105843_create_versions.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# This migration creates the `versions` table, the only schema PT requires.
# All other migrations PT provides are optional.
class CreateVersions < ActiveRecord::Migration[7.0]

# The largest text column available in all supported RDBMS is
# 1024^3 - 1 bytes, roughly one gibibyte. We specify a size
# so that MySQL will use `longtext` instead of `text`. Otherwise,
# when serializing very large objects, `text` might not be big enough.
TEXT_BYTES = 1_073_741_823

def change
create_table :versions do |t|
t.string :item_type, null: false
t.bigint :item_id, null: false
t.string :event, null: false
t.string :whodunnit
t.text :object, limit: TEXT_BYTES

# Known issue in MySQL: fractional second precision
# -------------------------------------------------
#
# MySQL timestamp columns do not support fractional seconds unless
# defined with "fractional seconds precision". MySQL users should manually
# add fractional seconds precision to this migration, specifically, to
# the `created_at` column.
# (https://dev.mysql.com/doc/refman/5.6/en/fractional-seconds.html)
#
# MySQL users should also upgrade to at least rails 4.2, which is the first
# version of ActiveRecord with support for fractional seconds in MySQL.
# (https://github.com/rails/rails/pull/14359)
#
# MySQL users should use the following line for `created_at`
# t.datetime :created_at, limit: 6
t.datetime :created_at
end
add_index :versions, %i(item_type item_id)
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
# This migration comes from active_storage (originally 20170806125915)
class CreateActiveStorageTables < ActiveRecord::Migration[5.2]
def change
# Use Active Record's configured type for primary and foreign keys
primary_key_type, foreign_key_type = primary_and_foreign_key_types

create_table :active_storage_blobs, id: primary_key_type do |t|
t.string :key, null: false
t.string :filename, null: false
t.string :content_type
t.text :metadata
t.string :service_name, null: false
t.bigint :byte_size, null: false
t.string :checksum

if connection.supports_datetime_with_precision?
t.datetime :created_at, precision: 6, null: false
else
t.datetime :created_at, null: false
end

t.index [ :key ], unique: true
end

create_table :active_storage_attachments, id: primary_key_type do |t|
t.string :name, null: false
t.references :record, null: false, polymorphic: true, index: false, type: foreign_key_type
t.references :blob, null: false, type: foreign_key_type

if connection.supports_datetime_with_precision?
t.datetime :created_at, precision: 6, null: false
else
t.datetime :created_at, null: false
end

t.index [ :record_type, :record_id, :name, :blob_id ], name: :index_active_storage_attachments_uniqueness, unique: true
t.foreign_key :active_storage_blobs, column: :blob_id
end

create_table :active_storage_variant_records, id: primary_key_type do |t|
t.belongs_to :blob, null: false, index: false, type: foreign_key_type
t.string :variation_digest, null: false

t.index [ :blob_id, :variation_digest ], name: :index_active_storage_variant_records_uniqueness, unique: true
t.foreign_key :active_storage_blobs, column: :blob_id
end
end

private
def primary_and_foreign_key_types
config = Rails.configuration.generators
setting = config.options[config.orm][:primary_key_type]
primary_key_type = setting || :primary_key
foreign_key_type = setting || :bigint
[primary_key_type, foreign_key_type]
end
end
13 changes: 13 additions & 0 deletions db/migrate/20231107104313_create_categories.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
class CreateCategories < ActiveRecord::Migration[7.1]
def change
create_table :categories do |t|
t.string :name
t.timestamps
end

create_table :categories_packages, id: false do |t|
t.belongs_to :category
t.belongs_to :package
end
end
end
22 changes: 22 additions & 0 deletions db/migrate/20231107184816_create_delayed_jobs.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
class CreateDelayedJobs < ActiveRecord::Migration[7.1]
def self.up
create_table :delayed_jobs do |table|
table.integer :priority, default: 0, null: false # Allows some jobs to jump to the front of the queue
table.integer :attempts, default: 0, null: false # Provides for retries, but still fail eventually.
table.text :handler, null: false # YAML-encoded string of the object that will do work
table.text :last_error # reason for last failure (See Note below)
table.datetime :run_at # When to run. Could be Time.zone.now for immediately, or sometime in the future.
table.datetime :locked_at # Set when a client is working on this object
table.datetime :failed_at # Set when all retries have failed (actually, by default, the record is deleted instead)
table.string :locked_by # Who is working on this object (if locked)
table.string :queue # The name of the queue this job is in
table.timestamps null: true
end

add_index :delayed_jobs, [:priority, :run_at], name: "delayed_jobs_priority"
end

def self.down
drop_table :delayed_jobs
end
end
5 changes: 5 additions & 0 deletions db/migrate/20231107201407_add_weight_to_package.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class AddWeightToPackage < ActiveRecord::Migration[7.1]
def change
add_column :packages, :weight, :integer, default: 100
end
end
121 changes: 121 additions & 0 deletions db/schema.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
# This file is auto-generated from the current state of the database. Instead
# of editing this file, please use the migrations feature of Active Record to
# incrementally modify your database, and then regenerate this schema definition.
#
# This file is the source Rails uses to define your schema when running `bin/rails
# db:schema:load`. When creating a new database, `bin/rails db:schema:load` tends to
# be faster and is potentially less error prone than running all of your
# migrations from scratch. Old migrations may fail to apply correctly if those
# migrations use external dependencies or application code.
#
# It's strongly recommended that you check this file into your version control system.

ActiveRecord::Schema[7.1].define(version: 2023_11_07_201407) do
# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"

create_table "active_storage_attachments", force: :cascade do |t|
t.string "name", null: false
t.string "record_type", null: false
t.bigint "record_id", null: false
t.bigint "blob_id", null: false
t.datetime "created_at", null: false
t.index ["blob_id"], name: "index_active_storage_attachments_on_blob_id"
t.index ["record_type", "record_id", "name", "blob_id"], name: "index_active_storage_attachments_uniqueness", unique: true
end

create_table "active_storage_blobs", force: :cascade do |t|
t.string "key", null: false
t.string "filename", null: false
t.string "content_type"
t.text "metadata"
t.string "service_name", null: false
t.bigint "byte_size", null: false
t.string "checksum"
t.datetime "created_at", null: false
t.index ["key"], name: "index_active_storage_blobs_on_key", unique: true
end

create_table "active_storage_variant_records", force: :cascade do |t|
t.bigint "blob_id", null: false
t.string "variation_digest", null: false
t.index ["blob_id", "variation_digest"], name: "index_active_storage_variant_records_uniqueness", unique: true
end

create_table "categories", force: :cascade do |t|
t.string "name"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
end

create_table "categories_packages", id: false, force: :cascade do |t|
t.bigint "category_id"
t.bigint "package_id"
t.index ["category_id"], name: "index_categories_packages_on_category_id"
t.index ["package_id"], name: "index_categories_packages_on_package_id"
end

create_table "delayed_jobs", force: :cascade do |t|
t.integer "priority", default: 0, null: false
t.integer "attempts", default: 0, null: false
t.text "handler", null: false
t.text "last_error"
t.datetime "run_at"
t.datetime "locked_at"
t.datetime "failed_at"
t.string "locked_by"
t.string "queue"
t.datetime "created_at"
t.datetime "updated_at"
t.index ["priority", "run_at"], name: "delayed_jobs_priority"
end

create_table "distributions", force: :cascade do |t|
t.string "vendor"
t.string "name"
t.string "url"
t.string "obs_repo_names"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
end

create_table "packages", force: :cascade do |t|
t.string "name"
t.string "release"
t.string "architectures"
t.string "license"
t.string "url"
t.string "title"
t.string "summary"
t.text "description"
t.boolean "appstream", default: false
t.bigint "repository_id"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.integer "weight", default: 100
t.index ["repository_id"], name: "index_packages_on_repository_id"
end

create_table "repositories", force: :cascade do |t|
t.string "url"
t.boolean "updateinfo", default: false
t.string "revision"
t.bigint "distribution_id"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.index ["distribution_id"], name: "index_repositories_on_distribution_id"
end

create_table "versions", force: :cascade do |t|
t.string "item_type", null: false
t.bigint "item_id", null: false
t.string "event", null: false
t.string "whodunnit"
t.text "object"
t.datetime "created_at"
t.index ["item_type", "item_id"], name: "index_versions_on_item_type_and_item_id"
end

add_foreign_key "active_storage_attachments", "active_storage_blobs", column: "blob_id"
add_foreign_key "active_storage_variant_records", "active_storage_blobs", column: "blob_id"
end

0 comments on commit 64aed3f

Please sign in to comment.