Club come entità principale, branding e fix infrastruttura streaming.
Introduce clubs con abbonamento, branding Active Storage e flusso registrazione società; corregge healthcheck MediaMTX (immagine distroless) e allinea dominio produzione matchlivetv.it. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -0,0 +1,60 @@
|
||||
class CreateClubsAndBranding < ActiveRecord::Migration[7.2]
|
||||
def up
|
||||
create_table :clubs, id: :uuid do |t|
|
||||
t.string :name, null: false
|
||||
t.string :sport, null: false, default: "volleyball"
|
||||
t.string :logo_url
|
||||
t.string :primary_color, null: false, default: "#e53935"
|
||||
t.string :secondary_color, null: false, default: "#ffffff"
|
||||
t.timestamps
|
||||
end
|
||||
|
||||
create_table :club_memberships, id: :uuid do |t|
|
||||
t.references :user, type: :uuid, null: false, foreign_key: true
|
||||
t.references :club, type: :uuid, null: false, foreign_key: true
|
||||
t.string :role, null: false, default: "owner"
|
||||
t.timestamps
|
||||
end
|
||||
add_index :club_memberships, %i[user_id club_id], unique: true
|
||||
|
||||
add_reference :teams, :club, type: :uuid, foreign_key: true
|
||||
add_column :teams, :primary_color, :string
|
||||
add_column :teams, :secondary_color, :string
|
||||
|
||||
migrate_teams_to_clubs
|
||||
|
||||
change_column_null :teams, :club_id, false
|
||||
end
|
||||
|
||||
def down
|
||||
change_column_null :teams, :club_id, true
|
||||
remove_column :teams, :secondary_color
|
||||
remove_column :teams, :primary_color
|
||||
remove_reference :teams, :club
|
||||
drop_table :club_memberships
|
||||
drop_table :clubs
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def migrate_teams_to_clubs
|
||||
say_with_time "Migrazione squadre → società" do
|
||||
Team.find_each do |team|
|
||||
owner_ut = UserTeam.find_by(team: team, role: "owner")
|
||||
next unless owner_ut
|
||||
|
||||
club = Club.create!(
|
||||
name: team.name,
|
||||
sport: team.sport,
|
||||
logo_url: team.logo_url,
|
||||
primary_color: "#e53935",
|
||||
secondary_color: "#ffffff"
|
||||
)
|
||||
ClubMembership.find_or_create_by!(user: owner_ut.user, club: club) do |m|
|
||||
m.role = "owner"
|
||||
end
|
||||
team.update!(club: club)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,32 @@
|
||||
class MoveSubscriptionsToClubs < ActiveRecord::Migration[7.2]
|
||||
def up
|
||||
unless column_exists?(:subscriptions, :club_id)
|
||||
add_reference :subscriptions, :club, type: :uuid, foreign_key: true, index: { unique: true }
|
||||
end
|
||||
|
||||
execute <<~SQL.squish
|
||||
UPDATE subscriptions SET club_id = teams.club_id
|
||||
FROM teams WHERE subscriptions.team_id = teams.id AND subscriptions.club_id IS NULL
|
||||
SQL
|
||||
|
||||
if column_exists?(:subscriptions, :team_id)
|
||||
remove_index :subscriptions, :team_id if index_exists?(:subscriptions, :team_id)
|
||||
remove_reference :subscriptions, :team
|
||||
end
|
||||
|
||||
change_column_null :subscriptions, :club_id, false if column_exists?(:subscriptions, :club_id)
|
||||
end
|
||||
|
||||
def down
|
||||
add_reference :subscriptions, :team, type: :uuid, foreign_key: true, index: { unique: true } unless column_exists?(:subscriptions, :team_id)
|
||||
|
||||
execute <<~SQL.squish
|
||||
UPDATE subscriptions SET team_id = (
|
||||
SELECT teams.id FROM teams WHERE teams.club_id = subscriptions.club_id ORDER BY teams.created_at LIMIT 1
|
||||
)
|
||||
SQL
|
||||
|
||||
remove_reference :subscriptions, :club if column_exists?(:subscriptions, :club_id)
|
||||
change_column_null :subscriptions, :team_id, false
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,57 @@
|
||||
# This migration comes from active_storage (originally 20170806125915)
|
||||
class CreateActiveStorageTables < ActiveRecord::Migration[7.0]
|
||||
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
|
||||
66
backend/db/schema.rb
generated
66
backend/db/schema.rb
generated
@@ -10,11 +10,39 @@
|
||||
#
|
||||
# It's strongly recommended that you check this file into your version control system.
|
||||
|
||||
ActiveRecord::Schema[7.2].define(version: 2026_05_27_140000) do
|
||||
ActiveRecord::Schema[7.2].define(version: 2026_05_27_160101) do
|
||||
# These are extensions that must be enabled in order to support this database
|
||||
enable_extension "pgcrypto"
|
||||
enable_extension "plpgsql"
|
||||
|
||||
create_table "active_storage_attachments", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t|
|
||||
t.string "name", null: false
|
||||
t.string "record_type", null: false
|
||||
t.uuid "record_id", null: false
|
||||
t.uuid "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", id: :uuid, default: -> { "gen_random_uuid()" }, 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", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t|
|
||||
t.uuid "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 "admin_accounts", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t|
|
||||
t.string "username", null: false
|
||||
t.string "password_digest", null: false
|
||||
@@ -23,6 +51,27 @@ ActiveRecord::Schema[7.2].define(version: 2026_05_27_140000) do
|
||||
t.index ["username"], name: "index_admin_accounts_on_username", unique: true
|
||||
end
|
||||
|
||||
create_table "club_memberships", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t|
|
||||
t.uuid "user_id", null: false
|
||||
t.uuid "club_id", null: false
|
||||
t.string "role", default: "owner", null: false
|
||||
t.datetime "created_at", null: false
|
||||
t.datetime "updated_at", null: false
|
||||
t.index ["club_id"], name: "index_club_memberships_on_club_id"
|
||||
t.index ["user_id", "club_id"], name: "index_club_memberships_on_user_id_and_club_id", unique: true
|
||||
t.index ["user_id"], name: "index_club_memberships_on_user_id"
|
||||
end
|
||||
|
||||
create_table "clubs", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t|
|
||||
t.string "name", null: false
|
||||
t.string "sport", default: "volleyball", null: false
|
||||
t.string "logo_url"
|
||||
t.string "primary_color", default: "#e53935", null: false
|
||||
t.string "secondary_color", default: "#ffffff", null: false
|
||||
t.datetime "created_at", null: false
|
||||
t.datetime "updated_at", null: false
|
||||
end
|
||||
|
||||
create_table "device_states", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t|
|
||||
t.uuid "stream_session_id", null: false
|
||||
t.string "device_role", null: false
|
||||
@@ -133,7 +182,6 @@ ActiveRecord::Schema[7.2].define(version: 2026_05_27_140000) do
|
||||
end
|
||||
|
||||
create_table "subscriptions", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t|
|
||||
t.uuid "team_id", null: false
|
||||
t.uuid "plan_id", null: false
|
||||
t.string "status", default: "active", null: false
|
||||
t.string "stripe_customer_id"
|
||||
@@ -143,9 +191,10 @@ ActiveRecord::Schema[7.2].define(version: 2026_05_27_140000) do
|
||||
t.boolean "cancel_at_period_end", default: false, null: false
|
||||
t.datetime "created_at", null: false
|
||||
t.datetime "updated_at", null: false
|
||||
t.uuid "club_id", null: false
|
||||
t.index ["club_id"], name: "index_subscriptions_on_club_id", unique: true
|
||||
t.index ["plan_id"], name: "index_subscriptions_on_plan_id"
|
||||
t.index ["stripe_subscription_id"], name: "index_subscriptions_on_stripe_subscription_id", unique: true, where: "(stripe_subscription_id IS NOT NULL)"
|
||||
t.index ["team_id"], name: "index_subscriptions_on_team_id", unique: true
|
||||
end
|
||||
|
||||
create_table "team_invitations", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t|
|
||||
@@ -170,6 +219,10 @@ ActiveRecord::Schema[7.2].define(version: 2026_05_27_140000) do
|
||||
t.string "logo_url"
|
||||
t.datetime "created_at", null: false
|
||||
t.datetime "updated_at", null: false
|
||||
t.uuid "club_id", null: false
|
||||
t.string "primary_color"
|
||||
t.string "secondary_color"
|
||||
t.index ["club_id"], name: "index_teams_on_club_id"
|
||||
end
|
||||
|
||||
create_table "user_teams", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t|
|
||||
@@ -210,6 +263,10 @@ ActiveRecord::Schema[7.2].define(version: 2026_05_27_140000) do
|
||||
t.index ["team_id"], name: "index_youtube_credentials_on_team_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"
|
||||
add_foreign_key "club_memberships", "clubs"
|
||||
add_foreign_key "club_memberships", "users"
|
||||
add_foreign_key "device_states", "stream_sessions"
|
||||
add_foreign_key "matches", "teams"
|
||||
add_foreign_key "recordings", "stream_sessions"
|
||||
@@ -218,9 +275,10 @@ ActiveRecord::Schema[7.2].define(version: 2026_05_27_140000) do
|
||||
add_foreign_key "stream_events", "stream_sessions"
|
||||
add_foreign_key "stream_sessions", "matches"
|
||||
add_foreign_key "stream_sessions", "users"
|
||||
add_foreign_key "subscriptions", "clubs"
|
||||
add_foreign_key "subscriptions", "plans"
|
||||
add_foreign_key "subscriptions", "teams"
|
||||
add_foreign_key "team_invitations", "teams"
|
||||
add_foreign_key "teams", "clubs"
|
||||
add_foreign_key "user_teams", "teams"
|
||||
add_foreign_key "user_teams", "users"
|
||||
add_foreign_key "youtube_credentials", "teams"
|
||||
|
||||
@@ -16,14 +16,21 @@ admin = User.find_or_create_by!(email: "admin@matchlivetv.test") do |u|
|
||||
u.role = "admin"
|
||||
end
|
||||
|
||||
team = Team.find_or_create_by!(name: "Tigers Volley") do |t|
|
||||
club = Club.find_or_create_by!(name: "Tigers Volley") do |c|
|
||||
c.sport = "volleyball"
|
||||
c.primary_color = "#e53935"
|
||||
c.secondary_color = "#ffffff"
|
||||
end
|
||||
|
||||
ClubMembership.find_or_create_by!(user: coach, club: club) { |m| m.role = "owner" }
|
||||
|
||||
team = club.teams.find_or_create_by!(name: "Under 16") do |t|
|
||||
t.sport = "volleyball"
|
||||
end
|
||||
|
||||
UserTeam.find_or_create_by!(user: coach, team: team) { |ut| ut.role = "owner" }
|
||||
UserTeam.find_or_create_by!(user: admin, team: team) { |ut| ut.role = "member" }
|
||||
|
||||
Billing::AssignPlan.call(team: team, plan_slug: "free") unless team.subscription
|
||||
Billing::AssignPlan.call(club: club, plan_slug: "free") unless club.subscription
|
||||
|
||||
match = team.matches.find_or_create_by!(opponent_name: "ASD Eagles Pavia") do |m|
|
||||
m.location = "PalaTigers - Milano"
|
||||
@@ -35,4 +42,4 @@ match = team.matches.find_or_create_by!(opponent_name: "ASD Eagles Pavia") do |m
|
||||
end
|
||||
|
||||
puts "Seed OK: coach@matchlivetv.test / password123"
|
||||
puts "Team: #{team.name}, Match: #{match.opponent_name}"
|
||||
puts "Club: #{club.name}, Team: #{team.name}, Match: #{match.opponent_name}"
|
||||
|
||||
Reference in New Issue
Block a user