Initial commit

This commit is contained in:
Senad Uka
2020-05-31 22:38:19 +02:00
commit 858fafc3c5
1280 changed files with 65918 additions and 0 deletions

View File

@@ -0,0 +1,9 @@
class PopulateReleasableTypeForFileInfos < ActiveRecord::DataMigration
def up
say "Populating FileInfo releasable type"
FileInfo.update_all(releasable_type: "AcquiredMediaRelease")
say "Done."
end
end

View File

@@ -0,0 +1,28 @@
class MoveMusicReleaseConfirmationsToAudioConfirmations < ActiveRecord::DataMigration
def up
say "Moving Music Release Confirmations to Audio Confirmations"
VideoReleaseConfirmation.where(releasable_type: "MusicRelease").find_each do |music_release_confirmation|
AudioConfirmation.create!(
video_id: music_release_confirmation.video_id,
channel: music_release_confirmation.channel,
timecode_in: music_release_confirmation.timecode_in,
timecode_out: music_release_confirmation.timecode_out,
duration: music_release_confirmation.duration,
source_file_name: music_release_confirmation.source_file_name,
clip_name: music_release_confirmation.clip_name,
description: music_release_confirmation.description,
time_elapsed: music_release_confirmation.time_elapsed,
music_type: music_release_confirmation.music_type,
music_category: music_release_confirmation.music_category,
composer_info: music_release_confirmation.releasable.composers.map { |composer| "#{composer.name}, #{composer.affiliation}, #{composer.percentage}%" }.join("|"),
publisher_info: music_release_confirmation.releasable.publishers.map { |publisher| "#{publisher.name}, #{publisher.affiliation}, #{publisher.percentage}%" }.join("|"),
catalog: "",
title: "",
time_elapsed: music_release_confirmation.time_elapsed,
)
end
say "Done."
end
end

View File

@@ -0,0 +1,9 @@
class RemoveMusicReleaseConfirmations < ActiveRecord::DataMigration
def up
say "Removing MusicReleaseConfirmations"
VideoReleaseConfirmation.where(releasable_type: "MusicRelease").destroy_all
say "Done."
end
end

View File

@@ -0,0 +1,9 @@
class UpdatePlanUidsToMeSuite < ActiveRecord::DataMigration
def up
say "Migrating Plan UIDs to all be me_suite"
Account.update_all(plan_uid: "me_suite")
say "Done."
end
end

View File

@@ -0,0 +1,17 @@
class SetGraphicTypeForGraphicElements < ActiveRecord::DataMigration
def up
say "Setting #graphic_type for GraphicElements.."
GraphicsElement.update_all(graphic_type: "Other")
say "Done."
end
def down
say "Unsetting #graphic_type for GraphicElements.."
GraphicsElement.update_all(graphic_type: nil)
say "Done."
end
end

View File

@@ -0,0 +1,22 @@
class SetTerritoryAndTermForAcquiredMediaReleases < ActiveRecord::DataMigration
def up
say "Setting AcquiredMediaRelease#term and #territory.."
AcquiredMediaRelease.find_each do |acquired_media_release|
acquired_media_release.update(
term: Term.find_by(label: acquired_media_release.term_old),
territory: Territory.find_by(label: acquired_media_release.territory_old),
)
end
say "Done."
end
def down
say "Un-setting AcquiredMediaRelease#term and #territory.."
AcquiredMediaRelease.update_all(term: nil, territory: nil)
say "Done."
end
end

View File

@@ -0,0 +1,32 @@
class ConvertReleasableNotesToCollection < ActiveRecord::DataMigration
RELEASABLE_TYPES = [
TalentRelease,
AppearanceRelease,
LocationRelease,
AcquiredMediaRelease,
MaterialRelease,
MusicRelease,
]
def up
RELEASABLE_TYPES.each { |type| convert_notes_to_collection_for(type) }
say "Done."
end
private
def convert_notes_to_collection_for(releasable_type)
say "Converting #{releasable_type}#notes to collection..."
releasable_type.where.not(notes_old: nil).find_each do |releasable|
content = releasable[:notes_old]
user = releasable.project.account.users.order(:created_at).first
Note.create(content: content, user: user, notable: releasable)
end
end
class Note < ActiveRecord::Base
belongs_to :user
belongs_to :notable, polymorphic: true
end
end

View File

@@ -0,0 +1,33 @@
# frozen_string_literal: true
class NewPermissionSystem < ActiveRecord::DataMigration
def up
say 'Creating AccountAuths and ProjectMemberships for existing Projects...'
User.all.each do |user|
next if user.account_id_old.nil?
role = user.role_old == 0 ? :associate : :account_manager
account = Account.find(user.account_id_old)
# Create a membership to the account for the user
AccountAuth.create(user: user, account: account, role: role)
# If the user is not an account manager, create a membership to each project in the account for the user
if role != :account_manager
account.projects.each do |project|
ProjectMembership.create!(project: project, user: user)
end
end
end
say 'Done.'
end
def down
say 'Destroying new permission system artifacts'
ProjectMembership.destroy_all
AccountAuth.destroy_all
say 'Done.'
end
end

View File

@@ -0,0 +1,13 @@
class ChangePermissionsCustomFolders < ActiveRecord::DataMigration
def up
say 'Changing permissions of custom folders for existing records...'
project_manager_directory_ids = Directory.where(permissions: "Account Managers Only").map(&:id)
account_manager_directory_ids = Directory.where(permissions: "Account Managers & Project Managers").map(&:id)
Directory.where(id: project_manager_directory_ids).update_all(permissions: "Account Managers & Project Managers")
Directory.where(id: account_manager_directory_ids).update_all(permissions: "Account Managers Only")
say 'Done'
end
end

View File

@@ -0,0 +1,17 @@
class MigrateInternalTags < ActiveRecord::DataMigration
def up
say 'Migrating tag context to internal tags list...'
ActsAsTaggableOn::Tagging.update_all(context: "internal_tags")
say 'Done'
end
def down
say 'Migrating tag context back to default tags list...'
ActsAsTaggableOn::Tagging.update_all(context: "tags")
say 'Done'
end
end

View File

@@ -0,0 +1,5 @@
class MakeContractTemplatesFeesValid < ActiveRecord::DataMigration
def up
ContractTemplate.where("fee_cents < 0 or fee_cents > 9999999999").update_all("fee_cents = 0")
end
end

View File

@@ -0,0 +1,17 @@
class MigratePersonNameFieldForAllReleases < ActiveRecord::DataMigration
RELEASES = ["AcquiredMediaRelease", "AppearanceRelease", "LocationRelease", "MaterialRelease", "MusicRelease", "TalentRelease"]
def up
say 'Migrating person name ...'
RELEASES.each do |release|
release.constantize.find_each do |record|
if record.person_name_old.present?
record.update(person_name: record.person_name_old)
end
end
end
say 'Done'
end
end

View File

@@ -0,0 +1,17 @@
class MigrateGuardianNameForAllReleases < ActiveRecord::DataMigration
RELEASES = ["AppearanceRelease", "TalentRelease"]
def up
say 'Migrating guardian name ...'
RELEASES.each do |release|
release.constantize.find_each do |record|
if record.guardian_name_old.present?
record.update(guardian_name: record.guardian_name_old)
end
end
end
say 'Done'
end
end

View File

@@ -0,0 +1,21 @@
class SetEmailForNotes < ActiveRecord::DataMigration
def up
say "Setting #email for Notes..."
Note.find_each do |note|
if note.user.present? && note.user.email.present?
note.update_column(:email, note.user.email)
end
end
say "Done."
end
def down
say "Unsetting #email for Notes..."
Note.update_all(email: nil)
say "Done."
end
end

View File

@@ -0,0 +1,7 @@
class GenerateTokensForExistingBroadcasts < ActiveRecord::DataMigration
def up
Broadcast.where(token: nil).each do |broadcast|
broadcast.regenerate_token
end
end
end

View File

@@ -0,0 +1,14 @@
# frozen_string_literal: true
class GiveNamesToImportedAppearanceReleases < ActiveRecord::DataMigration
def up
AppearanceRelease.where(person_first_name: nil).each do |ar|
contract_no = AppearanceRelease.random_contract_number.to_s
if ar.person_photo.attached?
ar.update(person_first_name: I18n.t('appearance_releases.shared.imported_appearance_release_headshot_name'), person_last_name: contract_no)
else
ar.update(person_first_name: I18n.t('appearance_releases.shared.imported_appearance_release_contract_name'), person_last_name: contract_no)
end
end
end
end

View File

@@ -0,0 +1,16 @@
class AssignZoomMeetingsToProjects < ActiveRecord::DataMigration
def up
ZoomMeeting.find_each do |zm|
if zm.respond_to?(:broadcast_id) && zm.broadcast_id.present?
broadcast = Broadcast.find_by(id: zm.broadcast_id)
if broadcast.present?
zm.update_column(:project_id, broadcast.project_id)
end
end
end
end
def down
ZoomMeeting.update_all(project_id: nil)
end
end

View File

@@ -0,0 +1,10 @@
class FixInvalidBroadcastStatuses < ActiveRecord::DataMigration
def up
say "Fixing invalid Broadcast#status..."
broadcasts_with_broken_statuses = Broadcast.where.not(status: Broadcast.statuses.values)
broadcasts_with_broken_statuses.update_all(status: nil)
say "Done."
end
end