Where do I fill in username and password for jugglingdb?

So my addon is finally movin onto production and I’m setting up a server to persist clients shared secret so that the relationship persists between reinstallations.

In the example “config.json” file, the “store” variable has a type-variable for the type of database, and a URL for the url to the database host. But where do I fill in username and password?

Example:

    "store": {
      // You won't want to use the memory store in production, or your install
      // registrations will be forgotten any time your app restarts.  Here
      // we tell atlassian-connect-express to use the PostgreSQL backend for the default
      // JugglingDB adapter.
      "type": "mysql",
      // Again, a PaaS host like Heroku will probably provide the db connection
      // URL to you through the environment, so we tell atlassian-connect-express to use that value.
      "url": "$DATABASE_URL"
    }

I would like to pass in three variables:
“username”:“$DATABASE_USER”,
“password”:“$DATABASE_PASSWORD”,
“database”:“$DATABASE_DB”

Also, if anyone could help me resolve the contradiction between the above instructions “You won’t want to use the memory store in production, or your install registrations will be forgotten any time your app restarts.” with the following from the documentation (under "Storing data without a database):

“Your add-on does not need to include a database to store data.
Your add-on could be written as a set of static web pages using only HTML, CSS and JavaScript, without any need for an application server. Your data will be stored against the host application entities.”

https://developer.atlassian.com/cloud/confluence/storing-data-without-a-database/

I’m very thankful for any reply.

Best regards

Hi, @alexander.sopov, you can pass all options (user, password, db) via URL:

dialect+driver://username:password@host:port/database replacing dialect+driver with mysql/postgres for jugglingdb and other variables like username, password, host, port and database.

Also instead of passing URL as a string directly in config.json you can set url via environment variable DATABASE_URL and keep $DATABASE_URL which refers to environment variable. (note you can name you environment variable whichever you want, just don’t forget to change it in config.json)

Now to the second question.

You won’t want to use the memory store in production, or your install registrations will be forgotten any time your app restarts.

This is about storing information needed by your server to be able to authenticate clients that installed your add-on.

Your add-on does not need to include a database to store data.
Your add-on could be written as a set of static web pages using only HTML, CSS and JavaScript, without any need for an application server. Your data will be stored against the host application entities.

This is about hosted storage. You can create add-ons that don’t have backend server like node.js or java server (static add-on’s), but then there is a problem where you can’t store any information like settings and maybe something else (you don’t have backend hence no database), so there is the hosted storage that provides some space for storing data in each JIRA instance that installed your add-on.
But even if you have backend server with database no one restrict you from using hosted storage for your needs

Basically it’s about two different things.
I recommend reading about connect authentication, which handled by frameworks like atlassian-connect-express or atlassian-connect-spring-boot and cloud architecture overview

3 Likes

Thank you very much for your replies <3

Alright, so the idea is that in a static web page-addon, there isn’t the same need to authenticate clients because all “backend-services”/code are handled in the client browser inside the iFrame and so storing the install registrations isn’t that much important?

Thanks for the links, I’ve read them through but I was disturbed by the seeming contradiction between the two statements, and I couldn’t get the database to connect with the ACE so I thought maybe I could skip it and just handle my DB on my own :stuck_out_tongue:

Ye, you got it right, i might be wrong in specific things, hope someone will correct me if i wrong, but in a whole that’s how it works

1 Like

Another question,

In the url example you specified, do I still need to prepend the dialect+driver:// in the “url” variable if I already specify mysql in the “type” variable in config.json?

Well, you can just try to start your application and see yourself :slight_smile:
I didn’t try it that way and never think of it, i have something like that (don’t look at adapter, i’m just using sequelize instead of jugglingdb):

"store": {
            "adapter": "sequelize",
            "type": "postgres",
            "url": "postgres://test_db_user:123@localhost:5432/test_db"
        }

Alright. Thank’s a lot.

Maybe I should make this into another topic, but I get the same error as before (but I didn’t bother much with it because I didn’t pass in username and password anyways so I thought it had something to do with that).

connection.connect err { Error: connect ECONNREFUSED 127.0.0.1:3306
    at Object.exports._errnoException (util.js:1018:11)
    at exports._exceptionWithHostPort (util.js:1041:20)
    at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1086:14)
    --------------------
    at Protocol._enqueue (/home/ubuntu/deploy/node_modules/mysql/lib/protocol/Protocol.js:145:48)
    at Protocol.handshake (/home/ubuntu/deploy/node_modules/mysql/lib/protocol/Protocol.js:52:23)
    at Connection.connect (/home/ubuntu/deploy/node_modules/mysql/lib/Connection.js:130:18)
    at initializeConnection (/home/ubuntu/deploy/node_modules/jugglingdb-mysql/lib/mysql.js:53:20)
    at Object.initializeSchema [as initialize] (/home/ubuntu/deploy/node_modules/jugglingdb-mysql/lib/mysql.js:34:5)
    at new Schema (/home/ubuntu/deploy/node_modules/jugglingdb/lib/schema.js:105:13)
    at /home/ubuntu/deploy/node_modules/atlassian-connect-express/lib/store/jugglingdb.js:34:32
    at lib$rsvp$$internal$$initializePromise (/home/ubuntu/deploy/node_modules/rsvp/dist/rsvp.js:1084:9)
    at new lib$rsvp$promise$$Promise (/home/ubuntu/deploy/node_modules/rsvp/dist/rsvp.js:546:53)
    at new JugglingDB (/home/ubuntu/deploy/node_modules/atlassian-connect-express/lib/store/jugglingdb.js:32:18)
    at module.exports (/home/ubuntu/deploy/node_modules/atlassian-connect-express/lib/store/jugglingdb.js:168:10)
    at Function.stores.create (/home/ubuntu/deploy/node_modules/atlassian-connect-express/lib/store/index.js:18:10)
    at stores (/home/ubuntu/deploy/node_modules/atlassian-connect-express/lib/store/index.js:12:17)
    at EventEmitter.Addon (/home/ubuntu/deploy/node_modules/atlassian-connect-express/lib/index.js:35:38)
    at module.exports (/home/ubuntu/deploy/node_modules/atlassian-connect-express/lib/index.js:209:12)
    at Object.<anonymous> (/home/ubuntu/deploy/app.js:25:13)
  code: 'ECONNREFUSED',
  errno: 'ECONNREFUSED',
  syscall: 'connect',
  address: '127.0.0.1',
  port: 3306,
  fatal: true }

It’s weird because I put in some custom code inside the ACE to print out the url-variable from the config.json and the url is correct so I don’t know why it’s trying to connect to 127.0.0.1)

Can you confirm that your database is running on port 3306?
127.0.0.1 is a localhost, so localhost:3306 is the same as 127.0.0.1:3306

yes, I’m able to connect to it manually and the database is not hosted locally, so the url is actually pointint to an external ip. That’s whats so confusing :S. I’m debugging it right now by trying to print out the “type” and “opts” variable in atlassian-connect-express/lib/store/jugglingdb.js:34:32

Hm, that’s odd, idk what can cause it since i just know that connection to that specific port was refused. I’d suggest you to use local database just to try to eliminate things

Thanks for the advice, man. I greatly apreciate it <3

I managed to solve it. The problem is that the Schema settings object for juggling DB has different variables than the one in config.json.

Here is a correct settings-object (which is the “store” object in config.json) example:

{
“type”: “$DB_TYPE”,
“host”: “$DB_URL”,
“username”:“$DB_USR”,
“password”:“$DB_PWD”,
“database”:“$DB_NAME”
}

as shown in this link:
http://1602.github.io/jugglingdb/schema.3.html

1 Like

One last question. Now that I’m connected to the database, I get errors about missing tables and stuff like that.

Do you know where I can find a list of tables I need to create in the database in order to avoid these errors?

I might forgot to tell, that URL would work for ACE connection to DB, because underhood they might parse this url or do whatever they want. Some db interfaces can connect just via URL, seems like it’s not applied to juggling.
So if you want to connect to your DB to store data you want (not data that ACE stores automatically) you need to use jugglingdb interface, so just url didn’t work.

Actually you don’t need to create any tables yourself that ACE needs (AddonSettings), ACE creates what it needs automatically, or is it errors caused by your schemas? Can you show me error log?

I traced the code. All it does is extract the “type” variable and then it passes the entire “store” object as the setting-parameter in the Schema constructor for jugglingdb. And that constructor does nothing with the “url” variable so that is why it defaulted to localhost.

About the “no tables” error I get. here’s the stacktrace:

{ Error: ER_NO_SUCH_TABLE: Table 'ColosseoClients.AddonSettings' doesn't exist
    at Query.Sequence._packetToError (/home/ubuntu/deploy/node_modules/mysql/lib/protocol/sequences/Sequence.js:52:14)
    at Query.ErrorPacket (/home/ubuntu/deploy/node_modules/mysql/lib/protocol/sequences/Query.js:77:18)
    at Protocol._parsePacket (/home/ubuntu/deploy/node_modules/mysql/lib/protocol/Protocol.js:279:23)
    at Parser.write (/home/ubuntu/deploy/node_modules/mysql/lib/protocol/Parser.js:76:12)
    at Protocol.write (/home/ubuntu/deploy/node_modules/mysql/lib/protocol/Protocol.js:39:16)
    at Socket.<anonymous> (/home/ubuntu/deploy/node_modules/mysql/lib/Connection.js:103:28)
    at emitOne (events.js:96:13)
    at Socket.emit (events.js:188:7)
    at readableAddChunk (_stream_readable.js:176:18)
    at Socket.Readable.push (_stream_readable.js:134:10)
    at TCP.onread (net.js:547:20)
    --------------------
    at Protocol._enqueue (/home/ubuntu/deploy/node_modules/mysql/lib/protocol/Protocol.js:145:48)
    at Connection.query (/home/ubuntu/deploy/node_modules/mysql/lib/Connection.js:208:25)
    at MySQL.query (/home/ubuntu/deploy/node_modules/jugglingdb-mysql/lib/mysql.js:150:17)
    at MySQL.<anonymous> (/home/ubuntu/deploy/node_modules/jugglingdb-mysql/lib/mysql.js:143:18)
    at emitNone (events.js:86:13)
    at Schema.emit (events.js:185:7)
    at Schema.<anonymous> (/home/ubuntu/deploy/node_modules/jugglingdb/lib/schema.js:121:14)
    at Query._callback (/home/ubuntu/deploy/node_modules/jugglingdb-mysql/lib/mysql.js:80:29)
    at Query.Sequence.end (/home/ubuntu/deploy/node_modules/mysql/lib/protocol/sequences/Sequence.js:88:24)
    at Query._handleFinalResultPacket (/home/ubuntu/deploy/node_modules/mysql/lib/protocol/sequences/Query.js:139:8)
    at Query.OkPacket (/home/ubuntu/deploy/node_modules/mysql/lib/protocol/sequences/Query.js:72:10)
    at Protocol._parsePacket (/home/ubuntu/deploy/node_modules/mysql/lib/protocol/Protocol.js:279:23)
    at Parser.write (/home/ubuntu/deploy/node_modules/mysql/lib/protocol/Parser.js:76:12)
    at Protocol.write (/home/ubuntu/deploy/node_modules/mysql/lib/protocol/Protocol.js:39:16)
    at Socket.<anonymous> (/home/ubuntu/deploy/node_modules/mysql/lib/Connection.js:103:28)
    at emitOne (events.js:96:13)
  code: 'ER_NO_SUCH_TABLE',
  errno: 1146,
  sqlMessage: 'Table \'ColosseoClients.AddonSettings\' doesn\'t exist',
  sqlState: '42S02',
  index: 0,
  sql: 'SHOW FIELDS FROM `AddonSettings`',
  query: 'SHOW FIELDS FROM `AddonSettings`' }

And right after that I get

Failed to initialize mysql storage adapter: Error: ER_NO_SUCH_TABLE: Table 'ColosseoClients.AddonSettings' doesn't exist
Error: ER_NO_SUCH_TABLE: Table 'ColosseoClients.AddonSettings' doesn't exist
    at Query.Sequence._packetToError (/home/ubuntu/deploy/node_modules/mysql/lib/protocol/sequences/Sequence.js:52:14)
    at Query.ErrorPacket (/home/ubuntu/deploy/node_modules/mysql/lib/protocol/sequences/Query.js:77:18)
    at Protocol._parsePacket (/home/ubuntu/deploy/node_modules/mysql/lib/protocol/Protocol.js:279:23)
    at Parser.write (/home/ubuntu/deploy/node_modules/mysql/lib/protocol/Parser.js:76:12)
    at Protocol.write (/home/ubuntu/deploy/node_modules/mysql/lib/protocol/Protocol.js:39:16)
    at Socket.<anonymous> (/home/ubuntu/deploy/node_modules/mysql/lib/Connection.js:103:28)
    at emitOne (events.js:96:13)
    at Socket.emit (events.js:188:7)
    at readableAddChunk (_stream_readable.js:176:18)
    at Socket.Readable.push (_stream_readable.js:134:10)
    at TCP.onread (net.js:547:20)
    --------------------
    at Protocol._enqueue (/home/ubuntu/deploy/node_modules/mysql/lib/protocol/Protocol.js:145:48)
    at Connection.query (/home/ubuntu/deploy/node_modules/mysql/lib/Connection.js:208:25)
    at MySQL.query (/home/ubuntu/deploy/node_modules/jugglingdb-mysql/lib/mysql.js:150:17)
    at MySQL.<anonymous> (/home/ubuntu/deploy/node_modules/jugglingdb-mysql/lib/mysql.js:143:18)
    at emitNone (events.js:86:13)
    at Schema.emit (events.js:185:7)
    at Schema.<anonymous> (/home/ubuntu/deploy/node_modules/jugglingdb/lib/schema.js:121:14)
    at Query._callback (/home/ubuntu/deploy/node_modules/jugglingdb-mysql/lib/mysql.js:80:29)
    at Query.Sequence.end (/home/ubuntu/deploy/node_modules/mysql/lib/protocol/sequences/Sequence.js:88:24)
    at Query._handleFinalResultPacket (/home/ubuntu/deploy/node_modules/mysql/lib/protocol/sequences/Query.js:139:8)
    at Query.OkPacket (/home/ubuntu/deploy/node_modules/mysql/lib/protocol/sequences/Query.js:72:10)
    at Protocol._parsePacket (/home/ubuntu/deploy/node_modules/mysql/lib/protocol/Protocol.js:279:23)
    at Parser.write (/home/ubuntu/deploy/node_modules/mysql/lib/protocol/Parser.js:76:12)
    at Protocol.write (/home/ubuntu/deploy/node_modules/mysql/lib/protocol/Protocol.js:39:16)
    at Socket.<anonymous> (/home/ubuntu/deploy/node_modules/mysql/lib/Connection.js:103:28)
    at emitOne (events.js:96:13)
Unhandled error: Error: ER_NO_SUCH_TABLE: Table 'ColosseoClients.AddonSettings' doesn't exist
    at Query.Sequence._packetToError (/home/ubuntu/deploy/node_modules/mysql/lib/protocol/sequences/Sequence.js:52:14)
    at Query.ErrorPacket (/home/ubuntu/deploy/node_modules/mysql/lib/protocol/sequences/Query.js:77:18)
    at Protocol._parsePacket (/home/ubuntu/deploy/node_modules/mysql/lib/protocol/Protocol.js:279:23)
    at Parser.write (/home/ubuntu/deploy/node_modules/mysql/lib/protocol/Parser.js:76:12)
    at Protocol.write (/home/ubuntu/deploy/node_modules/mysql/lib/protocol/Protocol.js:39:16)
    at Socket.<anonymous> (/home/ubuntu/deploy/node_modules/mysql/lib/Connection.js:103:28)
    at emitOne (events.js:96:13)
    at Socket.emit (events.js:188:7)
    at readableAddChunk (_stream_readable.js:176:18)
    at Socket.Readable.push (_stream_readable.js:134:10)
    at TCP.onread (net.js:547:20)
    --------------------
    at Protocol._enqueue (/home/ubuntu/deploy/node_modules/mysql/lib/protocol/Protocol.js:145:48)
    at Connection.query (/home/ubuntu/deploy/node_modules/mysql/lib/Connection.js:208:25)
    at MySQL.query (/home/ubuntu/deploy/node_modules/jugglingdb-mysql/lib/mysql.js:150:17)
    at MySQL.<anonymous> (/home/ubuntu/deploy/node_modules/jugglingdb-mysql/lib/mysql.js:143:18)
    at emitNone (events.js:86:13)
    at Schema.emit (events.js:185:7)
    at Schema.<anonymous> (/home/ubuntu/deploy/node_modules/jugglingdb/lib/schema.js:121:14)
    at Query._callback (/home/ubuntu/deploy/node_modules/jugglingdb-mysql/lib/mysql.js:80:29)
    at Query.Sequence.end (/home/ubuntu/deploy/node_modules/mysql/lib/protocol/sequences/Sequence.js:88:24)
    at Query._handleFinalResultPacket (/home/ubuntu/deploy/node_modules/mysql/lib/protocol/sequences/Query.js:139:8)
    at Query.OkPacket (/home/ubuntu/deploy/node_modules/mysql/lib/protocol/sequences/Query.js:72:10)
    at Protocol._parsePacket (/home/ubuntu/deploy/node_modules/mysql/lib/protocol/Protocol.js:279:23)
    at Parser.write (/home/ubuntu/deploy/node_modules/mysql/lib/protocol/Parser.js:76:12)
    at Protocol.write (/home/ubuntu/deploy/node_modules/mysql/lib/protocol/Protocol.js:39:16)
    at Socket.<anonymous> (/home/ubuntu/deploy/node_modules/mysql/lib/Connection.js:103:28)

Hey @alexander.sopov, sorry for missing :slight_smile:
I don’t know what can cause this issue, but i would try to create fresh new add-on with atlassian-connect-express scafolding and configure mysql database without any schemas, just to see if it’s working, to reduce sources of your problem

Edit: nvm, just read through your post about this problem :stuck_out_tongue:

1 Like