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:
Mark VanLandingham
2021-06-17 09:06:18 -05:00
committed by GitHub
parent ea2833d0d8
commit 0c42a29dc4
25 changed files with 222 additions and 96 deletions

View 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

View File

@ -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