Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

A question about creating tables in database for plugins? #3258

Open
sdbbs opened this issue Mar 20, 2023 · 6 comments
Open

A question about creating tables in database for plugins? #3258

sdbbs opened this issue Mar 20, 2023 · 6 comments

Comments

@sdbbs
Copy link

sdbbs commented Mar 20, 2023

I just wanted to note this, because it was difficult information for me to find - and to ask if I understand correctly.

I have an install of GitBucket 4.37.1 with H2 database. I am trying to experiment with plugins, and from https://github.com/takezoe/gitbucket-ci-plugin I realized that if you want to use class CISystemConfigs, a table called CI_SYSTEM_CONFIG needs to be created in the database - and it looks like, those databases are ultimately created by .xml files like resources/update/gitbucket-ci_1.4.0.xml:

<?xml version="1.0" encoding="UTF-8"?>
<changeSet>
    <createTable tableName="CI_SYSTEM_CONFIG">
        <column name="MAX_BUILD_HISTORY" type="int" nullable="false"/>
        <column name="MAX_PARALLEL_BUILDS" type="int" nullable="false"/>
    </createTable>

    <insert tableName="CI_SYSTEM_CONFIG">
        <column name="MAX_BUILD_HISTORY" value="20"/>
        <column name="MAX_PARALLEL_BUILDS" value="2"/>
    </insert>
</changeSet>

So, I tried doing something similar in my own plugin example, and it compiled ... and no new table.

Then I found https://github.com/nodamushi/gitbucket-exprettify-plugin which uses something similar, and tried to compile it. These are the changes needed so it compiles for gitbucket 4.37.1:

diff --git a/build.sbt b/build.sbt
index 5d7a955..e2fc843 100644
--- a/build.sbt
+++ b/build.sbt
@@ -1,5 +1,7 @@
 name := "gitbucket-exprettify-plugin"
 organization := "com.github.nodamushi"
 version := "0.0.1"
-scalaVersion := "2.12.4"
-gitbucketVersion := "4.19.0"
+//scalaVersion := "2.12.4"
+scalaVersion := "2.13.5"
+//gitbucketVersion := "4.19.0"
+gitbucketVersion := "4.37.1"
diff --git a/project/build.properties b/project/build.properties
index 059dc1f..7bb94aa 100644
--- a/project/build.properties
+++ b/project/build.properties
@@ -1 +1 @@
-sbt.version = 1.0.4
+sbt.version = 1.5.1
diff --git a/project/plugin.sbt b/project/plugin.sbt
index 504147f..575b7c7 100644
--- a/project/plugin.sbt
+++ b/project/plugin.sbt
@@ -1 +1 @@
-addSbtPlugin("io.github.gitbucket" % "sbt-gitbucket-plugin" % "1.2.0")
\ No newline at end of file
+addSbtPlugin("io.github.gitbucket" % "sbt-gitbucket-plugin" % "1.5.1")

Copied this to plugins/ - and new tables got immediately created!

However - then, for some reason, it is impossible to uninstall this gitbucket-exprettify-plugin from System administration/Plugins - and the Uninstall button to the right of the plugin; the plugin just stays there in the list, no matter how many times I click uninstall! And even the GitBucket log does not notice anything - it just prints this when I click Uninstall (and I also get the Info notification "gitbucket-exprettify-plugin was uninstalled." in the webpage):

03:01:46.464 [Thread-167] INFO  g.core.plugin.PluginWatchThread - Shutdown PluginWatchThread
03:01:46.546 [qtp636718812-15] INFO  gitbucket.core.plugin.PluginRegistry - Initialize gitbucket-gist-plugin-4.22.0.jar
03:01:46.632 [qtp636718812-15] INFO  gitbucket.core.plugin.PluginRegistry - Initialize gitbucket-emoji-plugin-4.6.0.jar
03:01:46.641 [qtp636718812-15] INFO  gitbucket.core.plugin.PluginRegistry - Initialize gitbucket-notifications-plugin-1.11.0.jar
03:01:46.690 [qtp636718812-15] INFO  gitbucket.core.plugin.PluginRegistry - Initialize gitbucket-pages-plugin-1.10.0.jar
03:01:46.725 [qtp636718812-15] INFO  gitbucket.core.plugin.PluginRegistry - Initialize gitbucket-exprettify-plugin-0.0.1.jar
03:01:46.749 [Thread-169] INFO  g.core.plugin.PluginWatchThread - Start PluginWatchThread: ......./GitBucket/plugins

So, I needed to delete gitbucket-exprettify-plugin manually; first from command line:

$ rm ....../GitBucket/plugins/gitbucket-exprettify-plugin-0.0.1.jar

Then, note that for H2 database, you should not use double quotes ( https://stackoverflow.com/questions/35646432/org-h2-jdbc-jdbcsqlexception-column-salman-not-found ); knowing that, we can first manually delete (from System administration/Database viewer) the two tables gitbucket-exprettify-plugin adds:

DROP TABLE EXPRETTIFY_LANGUAGE;
DROP TABLE EXPRETTIFY_PATTERN;

... and then I have to delete manually the entry in table VERSIONS:

DELETE FROM VERSIONS WHERE MODULE_ID = 'gitbucket-exprettify-plugin';

... and then, finally, t is seemingly uninstalled.

Then, I went to my plugin, and repeated this uninstall procedure - just the .jar file removal, and removal of entry from VERSIONS. Then I copied it to plugins/ again - and finally, I got my table created!

So, I was wondering:

  • Is this behavior of gitbucket-exprettify-plugin-0.0.1.jar under gitbucket 4.37.1 -- where it cannot be uninstalled via the uninstall button, requiring manual removal of tables and the entry from VERSIONS -- expected?
  • Also, I have noticed, that during all this time, the PLUGIN table is empty - is that also expected for gitbucket 4.37.1?
  • And should we expect that uninstalling a plugin should also automatically remove the tables it created for gitbucket 4.37.1 - or not? (that is, must we make sure to manually delete the corresponding tables, if we want to uninstall such plugins)?
@takezoe
Copy link
Member

takezoe commented Apr 23, 2023

However - then, for some reason, it is impossible to uninstall this gitbucket-exprettify-plugin

What your OS? Plugin Manager simply remove a JAR file and reload all plugins when Uninstall button is clicked but it could fail to remove files on Windows platform.

@takezoe
Copy link
Member

takezoe commented Apr 23, 2023

Is this behavior of gitbucket-exprettify-plugin-0.0.1.jar under gitbucket 4.37.1 -- where it cannot be uninstalled via the uninstall button, requiring manual removal of tables and the entry from VERSIONS -- expected?

My previous comment answered the first part of this question. And yes for requiring manual removal of created tables and the entry in VERSIONS table if you want a clean uninstallation.

@takezoe
Copy link
Member

takezoe commented Apr 23, 2023

Also, I have noticed, that during all this time, the PLUGIN table is empty - is that also expected for gitbucket 4.37.1?

Yes, PLUGIN table hasn't been used in since GitBucket 4.0.

@takezoe
Copy link
Member

takezoe commented Apr 23, 2023

And should we expect that uninstalling a plugin should also automatically remove the tables it created for gitbucket 4.37.1 - or not? (that is, must we make sure to manually delete the corresponding tables, if we want to uninstall such plugins)?

No. Tables created by plugins are not removed automatically even if plugins are uninstalled.

@takezoe
Copy link
Member

takezoe commented Apr 23, 2023

@sdbbs Sorry for my late answering. I just noticed the issue today. I would close this issue as I think I answered all of your questions for now. Please raise a new issue or send a message on Gitter if you have further questions.

@takezoe
Copy link
Member

takezoe commented Apr 23, 2023

I reopened the issue for visibility to plugin developers.

@takezoe takezoe reopened this Apr 23, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

No branches or pull requests

2 participants