How to make a plugin create a table in jira database

Hasnae E August 23, 2017

I've created a jira plugin in my own postgres database. For so, I needed to create a table in the jira database to save some informations (I called it environments). Now I'm trying to integrate it in another Jira software that uses mysql database.

What's really gonna be ideal is to write some script that make my table (environments) to be created automatically. I mean, is there an alternative to not create the table manually? Most of plugins do this but I have no idea how they do it. can anyone suggest me a tutorial or give me some good informations about this?

1 answer

1 accepted

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

2 votes
Answer accepted
Nic Brough -Adaptavist-
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
August 23, 2017

Use active objects - the plugins you've seen creating their own tables do it with tables named AO_<plugin key>_name.

See https://developer.atlassian.com/docs/atlassian-platform-common-components/active-objects

Hasnae E August 23, 2017

Thank you for the fast response. I'll do some reading about this active objects and come back to you. thanks again!

Hasnae E August 23, 2017

Actually i saw someone who created the table this way:

In entitymodel.xml he adds:

<entity entity-name="EnvTest" table-name="EnvTest" packagename="">
<field name="id" type="numeric"/>
<field name="name" type="long-varchar"/>
<field name="address" col-name="empaddress" type="long-varchar"/>
<field name="company" type="long-varchar"/>
<prim-key field="id"/>
<index name="emp_entity_name">
<index-field name="name"/>
</index>
</entity>

 

and in entitygroup.xml:
<entity-group group="default" entity="EnvTest"/>

 

I tried this but unfortunately this didn't work for me. Can you please tell me the reason why?

Nic Brough -Adaptavist-
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
August 23, 2017

That it a really bad way to do it.  This file is used when creating an empty JIRA database and for defining what to read out into an xml backup.  For an existing JIRA, you would need to manually create the table.

You'd then have to implement all the code required to read and write the table, and you would be unsopported by Atlassian.

Use the AO tables, they're not ideal for some uses, but they are the recommended approach.

Hasnae E August 25, 2017

Hi again,

So I have followed this tutorial you gave me: https://developer.atlassian.com/docs/atlassian-platform-common-components/active-objects/getting-started-with-active-objects

the plugin has been built succesfully and i downloaded it in my jira software but I didn't see any table created

Hasnae E August 25, 2017

When I run some script to list all the tables in my database (this script: SELECT table_schema,table_name FROM information_schema.tables ORDER BY table_schema,table_name;) I do see some tables names starting with AO, one of them is AO_5EFAF5_TODO. But when i run this script for exemple : select * from AO_5EFAF5_TODO;  I get this error : relation "ao_5efaf5_todo" does not exist. 

Hasnae E August 25, 2017

Okey I'm sorry it's working now!

Thank you so much.