Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in
Deleted user
0 / 0 points
Next:
badges earned

Your Points Tracker
Challenges
Leaderboard
  • Global
  • Feed

Badge for your thoughts?

You're enrolled in our new beta rewards program. Join our group to get the inside scoop and share your feedback.

Join group
Recognition
Give the gift of kudos
You have 0 kudos available to give
Who do you want to recognize?
Why do you want to recognize them?
Kudos
Great job appreciating your peers!
Check back soon to give more kudos.

Past Kudos Given
No kudos given
You haven't given any kudos yet. Share the love above and you'll see it here.

It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

atlassian-connect-express 7: working with Postgres

Hello!

In this article we will talk how to connect Postgres to our app.

The code will be based on this article.

You can find the source code for the article here.

You can find a video for this article here.

Our app by default stores information about all clients who installed our app. By default this data is stored in an in-memory database which means if we restart our app all registration data of our clients will be lost. It can be acceptable during development but it is definitely not acceptable during production mode.

That is why in this article we will see how to connect our app to Postgres.

I created a Postgres database with the following command:

docker run -p 5432:5432 --name tutorial_db -e POSTGRES_PASSWORD=password -d postgres

And then I created a database called “app”:

Screenshot 2021-05-24 at 11.05.53.png

Right now we have the following configuration for our database in the backend/config.json file:

"store": {
            "adapter": "sequelize",
            "dialect": "sqlite3",
            "type": "memory"
        },

As you can see we use an in-memory database. Now let’s change the configuration to this one:

"store": {
            "type": "postgres",
            "url": "$DATABASE_URL"
        },

Now we need to set the $DATABASE_URL parameter. We can do it by setting the DATABASE_URL environment variable, but for the sake of simplicity I will replace $DATABASE_URL with a database url:

 "url": "postgres://postgres:password@localhost:5432/app"

Now we need to add the pg dependency to our app and install it:

npm install --save-dev pg

Now let’s start our app:

npm start

It started successfuly.

If you look at the app database you will see that a new table called AddonSettings has been created:

Screenshot 2021-05-24 at 11.11.33.png

Right now the table is empty. Let’s install our app to Bitbucket and have a look what will change.

Here is how the table looks after I installed my app:

Screenshot 2021-05-24 at 11.14.11.png

You can see that we have a new line with the “clientInfo” key. This line was added by atlassian-connect-express and contains information about the client which lets atlassian-connect-express identify and validate requests from the client.

That is all for the article. See you next time.

1 comment

Mohammed Amine Community Leader Jun 03, 2021

Good information, thank you @Alexey Matveev _Appfire_ 

Comment

Log in or Sign up to comment
TAGS
Community showcase
Published in Marketplace Apps & Integrations

New cloud apps roundup - June 2021

Since our last roundup in April, Atlassian's Marketplace Partners have added over 100 new cloud apps to the Atlassian Marketplace to help your teams work more efficiently. Let’s take a quick look a...

426 views 5 12
Read article

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you