main
rb 22 lines 1.04 KB
Raw
1 class AddModelSupportAndStars < ActiveRecord::Migration[8.1]
2 def change
3 # A repository is either regular source code ("code") or a published set of
4 # open weights ("model") — the Hugging Face-style model library lives on the
5 # same git storage as everything else, distinguished only by this kind.
6 add_column :repositories, :kind, :string, null: false, default: "code"
7 add_index :repositories, :kind
8
9 # Cached counters so the discovery index can sort/show without extra queries.
10 add_column :repositories, :stars_count, :integer, null: false, default: 0
11 add_column :repositories, :downloads_count, :integer, null: false, default: 0
12
13 # Stars double as Hugging Face "likes" for models and GitHub-style stars for
14 # code repos — one row per (user, repository).
15 create_table :stars do |t|
16 t.references :user, null: false, foreign_key: true
17 t.references :repository, null: false, foreign_key: true
18 t.timestamps
19 end
20 add_index :stars, [ :user_id, :repository_id ], unique: true
21 end
22 end