Skip to content

Commit d49a4ef

Browse files
committed
Fix migrations references for tenant schemas
1 parent 36c191a commit d49a4ef

11 files changed

+36
-4
lines changed

db/migrate/20240605134916_add_notes_and_diary_comments_counter_caches.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
class AddNotesAndDiaryCommentsCounterCaches < ActiveRecord::Migration[7.1]
22
def self.up
3+
if connection.current_schema.start_with?("workspace-")
4+
return # Ignore this migration in workspace tenant schemas
5+
end
6+
37
add_column :users, :diary_comments_count, :integer, :default => 0
48
add_column :users, :note_comments_count, :integer, :default => 0
59

db/migrate/20240910175616_add_user_creation_address.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@ class AddUserCreationAddress < ActiveRecord::Migration[7.1]
22
disable_ddl_transaction!
33

44
def change
5+
if connection.current_schema.start_with?("workspace-")
6+
return # Ignore this migration in workspace tenant schemas
7+
end
8+
59
add_column :users, :creation_address, :inet
610
add_index :users, :creation_address, :using => :gist, :opclass => :inet_ops, :algorithm => :concurrently
711
end

db/migrate/20240912181413_backfill_user_creation_address.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@ class User < ApplicationRecord
33
end
44

55
def up
6+
if connection.current_schema.start_with?("workspace-")
7+
return # Ignore this migration in workspace tenant schemas
8+
end
9+
610
User
711
.where(:creation_address => nil)
812
.where.not(:creation_ip => nil)
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
class DropUserCreationIp < ActiveRecord::Migration[7.1]
22
def change
3+
if connection.current_schema.start_with?("workspace-")
4+
return # Ignore this migration in workspace tenant schemas
5+
end
6+
37
safety_assured { remove_column :users, :creation_ip, :string }
48
end
59
end

db/migrate/20241022141247_create_note_subscriptions.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
class CreateNoteSubscriptions < ActiveRecord::Migration[7.2]
22
def change
33
create_table :note_subscriptions, :primary_key => [:user_id, :note_id] do |t|
4-
t.references :user, :foreign_key => true, :index => false
4+
t.references :user, :foreign_key => { :to_table => "public.users" }, :index => false
55
t.references :note, :foreign_key => true
66
end
77
end
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
class AddUserLocationName < ActiveRecord::Migration[7.2]
22
def change
3+
if connection.current_schema.start_with?("workspace-")
4+
return # Ignore this migration in workspace tenant schemas
5+
end
6+
37
add_column :users, :home_location_name, :string
48
end
59
end

db/migrate/20250104140952_add_description_to_notes.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,6 @@ def change
44
add_column :notes, :user_id, :bigint
55
add_column :notes, :user_ip, :inet
66

7-
add_foreign_key :notes, :users, :column => :user_id, :name => "notes_user_id_fkey", :validate => false
7+
add_foreign_key :notes, "public.users", :column => :user_id, :name => "notes_user_id_fkey", :validate => false
88
end
99
end
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
class ValidateForeignKeyOnNotes < ActiveRecord::Migration[7.2]
22
def change
3-
validate_foreign_key :notes, :users
3+
validate_foreign_key :notes, "public.users"
44
end
55
end

db/migrate/20250217140049_create_social_links.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
class CreateSocialLinks < ActiveRecord::Migration[7.2]
22
def change
3+
if connection.current_schema.start_with?("workspace-")
4+
return # Ignore this migration in workspace tenant schemas
5+
end
6+
37
create_table :social_links do |t|
48
t.references :user, :null => false, :foreign_key => true
59
t.string :url, :null => false
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
class AddCompanyToUsers < ActiveRecord::Migration[8.0]
22
def change
3+
if connection.current_schema.start_with?("workspace-")
4+
return # Ignore this migration in workspace tenant schemas
5+
end
6+
37
add_column :users, :company, :string
48
end
59
end

0 commit comments

Comments
 (0)