Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in
Celebration

Earn badges and make progress

You're on your way to the next level! Join the Kudos program to earn points and save your progress.

Deleted user Avatar
Deleted user

Level 1: Seed

25 / 150 points

Next: Root

Avatar

1 badge earned

Collect

Participate in fun challenges

Challenges come and go, but your rewards stay with you. Do more to earn more!

Challenges
Coins

Gift kudos to your peers

What goes around comes around! Share the love by gifting kudos to your peers.

Recognition
Ribbon

Rise up in the ranks

Keep earning points to reach the top of the leaderboard. It resets every quarter so you always have a chance!

Leaderboard

Come for the products,
stay for the community

The Atlassian Community can help you and your team get more value out of Atlassian products and practices.

Atlassian Community about banner
4,556,693
Community Members
 
Community Events
184
Community Groups

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

M Amine
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
Jun 03, 2021

Good information, thank you @Alexey Matveev 

Comment

Log in or Sign up to comment
TAGS
AUG Leaders

Atlassian Community Events