# Adding jsonb columns for custom fields

**URL:** https://meta.discourse.org/t/adding-jsonb-columns-for-custom-fields/93418
**Category:** Development
**Created:** [July 29, 2018, 6:55pm UTC](https://meta.discourse.org/t/adding-jsonb-columns-for-custom-fields/93418 "2018-07-29T18:55:48Z")
**Posts on this page:** 1
**Showing post:** 7

<div class="post-metadata">

### Author: ![gdpelican](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/gdpelican/32/81308_2.png) [@gdpelican](https://meta.discourse.org/u/gdpelican)
#### Post date: [August 15, 2018, 2:07am UTC](https://meta.discourse.org/t/adding-jsonb-columns-for-custom-fields/93418/7 "2018-08-15T02:07:17Z")

</div>

I ended up doing this thing:

> [@New columns in directory (/users)](https://meta.discourse.org/t/new-columns-in-directory-users/77814/5):
>
> FWIW I’ve decided to go this route with a plugin of mine, where PluginStoreRow and CustomFields didn’t qqquite cut it on their own. warning Caveat emptor warning You should be trying really hard not to do this - It’s not recommended behaviour to modify the database from within a plugin, but it can be done unobtrusively in small, additive doses (I’d say you never for any reason want to remove or change existing columns) Here’s how I did it: Write a migration in the plugin which modifies th…

Which is adding (and allowing the removal of) a column from within the plugin (using this format to add and remove tables would be certainly possible as well).

The removal bit’s pretty manual atm, but maybe the registry you mention could handle removing related tables if the plugin is taken out of app.yml [it would be bad to wipe the database of all the plugin’s data just because the admin deactivated it] EDIT: No wait erasing data like that is probably a real nasty side effect and it probably wouldn’t be the worst thing in the world to have an orphan table or column that you could get rid of with a little work.

Code that might be cool to write:

```plaintext
# plugin.rb
register_plugin_table :my_plugin, :wingbats do |t|
  # this block is passed through to create_table
  t.integer :id 
  t.timestamps  
end

register_plugin_column :my_plugin, :post_custom_fields, :my_column, :jsonb, options: {
  default: {},
  index: true
}

```

---

_[View the full topic](https://meta.discourse.org/t/adding-jsonb-columns-for-custom-fields/93418)._
