mirror of
https://github.com/discourse/discourse.git
synced 2025-06-06 02:44:39 +08:00
DEV: Plugin API to allow creation of directory columns with item query (#13402)
The first thing we needed here was an enum rather than a boolean to determine how a directory_column was created. Now we have `automatic`, `user_field` and `plugin` directory columns. This plugin API is assuming that the plugin has added a migration to a column to the `directory_items` table. This was created to be initially used by discourse-solved. PR with API usage - https://github.com/discourse/discourse-solved/pull/137/
This commit is contained in:

committed by
GitHub

parent
ea2833d0d8
commit
0c42a29dc4
18
db/migrate/20210609133551_add_type_to_directory_columns.rb
Normal file
18
db/migrate/20210609133551_add_type_to_directory_columns.rb
Normal file
@ -0,0 +1,18 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
class AddTypeToDirectoryColumns < ActiveRecord::Migration[6.1]
|
||||
def up
|
||||
add_column :directory_columns, :type, :integer, default: 0, null: false
|
||||
|
||||
DB.exec(
|
||||
<<~SQL
|
||||
UPDATE directory_columns
|
||||
SET type = CASE WHEN automatic THEN 0 ELSE 1 END;
|
||||
SQL
|
||||
)
|
||||
end
|
||||
|
||||
def down
|
||||
remove_column :directory_columns, :type, :integer, default: 0, null: false
|
||||
end
|
||||
end
|
@ -0,0 +1,11 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
class RemoveDirectoryColumnAutomatic < ActiveRecord::Migration[6.1]
|
||||
def up
|
||||
remove_column :directory_columns, :automatic
|
||||
end
|
||||
|
||||
def down
|
||||
raise ActiveRecord::IrreversibleMigration
|
||||
end
|
||||
end
|
Reference in New Issue
Block a user