Skip to content

OpenProject is the leading open source project management software for product, project and portfolio management. A powerful Jira alternative with agile planning, issue tracking, roadmaps, Gantt charts, time tracking, collaboration features, and more. Available on premises or in the cloud. ⭐ Star us on GitHub

Improve migration for file links

Wieland Lindenthal8c1895eac70a
diff --git a/db/migrate/20220113144759_create_file_links.rb b/db/migrate/20220113144759_create_file_links.rb
index 2ca0014e67f..8156bca45f9 100644
--- a/db/migrate/20220113144759_create_file_links.rb
+++ b/db/migrate/20220113144759_create_file_links.rb
@@ -1,18 +1,28 @@
class CreateFileLinks < ActiveRecord::Migration[6.1]
def change
create_table :file_links do |t|
- t.references :storage, foreign_key: true
- t.bigint :creator, null: false, foreign_key: true
- t.bigint :container, null: false, foreign_key: true
- t.string :container_type
+ t.references :storage, foreign_key: true, on_delete: :cascade
+ t.references :creator,
+ null: false,
+ index: true,
+ foreign_key: { to_table: :users }
+ t.bigint :container_id, null: false
+ t.string :container_type, null: false
+
t.string :origin_id
t.string :origin_name
+ t.string :origin_created_by_name
+ t.string :origin_last_modified_by_name
t.string :origin_mime_type
t.timestamp :origin_created_at
t.timestamp :origin_updated_at
- t.string :origin_last_modified_by_name
t.timestamps
+
+ # i.e. show all file links per WP.
+ t.index [:container_id, :container_type]
+ # i.e. show all work packages per file.
+ t.index [:origin_id, :storage_id]
end
end
end