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
|
||||
Reference in New Issue
Block a user