Question

Why do I need to redeploy my app to see new db records?

Hi, I’m building a website using Python. I’ve linked the Python server to the dev PostgreSQL provided by the app Platform on digital ocean. Everything is working fine, but when I add new records to the dev db I have to redeploy the app to see the new records appearing on the home page. I want the new records to be available without the need for redeploying the app.

This is how my python script looks like:

import psycopg
from urllib.parse import parse_qs

# Create a connection to the SQLite database
def add_post(post_data):
    parsed_data = parse_qs(post_data)
    con = psycopg.connect("MY CONNECTION STRINGS")
    cur = con.cursor()

    name = parsed_data.get('name', [''])[0]
    date = parsed_data.get('date', [''])[0]
    place = parsed_data.get('place', [''])[0]
    link = parsed_data.get('link', [''])[0]
    category = parsed_data.get('category', [''])[0]
    description = parsed_data.get('description', [''][0])

    cur.execute("insert into events (poster, category, date, place, media, description)VALUES (%s, %s, %s, %s, %s, %s)", (name, category, date, place, link, description[0]))
    con.commit()
    con.close()

Submit an answer


This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

Sign In or Sign Up to Answer

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Bobby Iliev
Site Moderator
Site Moderator badge
November 9, 2023
Accepted Answer

Hi there,

It sounds like your app may be caching the database results, which would explain why you have to redeploy to see new records. When you redeploy, the cache is cleared, and your app queries the database again, pulling in the new records.

To solve this, you’ll need to adjust your application’s logic to query the database for new records dynamically, without relying on the state of the application when it was first deployed. Ensure that each request to your home page triggers a fresh database query or set up a timed cache invalidation strategy.

Check the part of your code that retrieves and displays records on the homepage. It should make a new connection and fetch the latest data each time the page is loaded or refreshed, not just when the app starts. If you’re using any form of caching, review your cache policy to ensure it doesn’t prevent updates from appearing immediately.

Feel free to share more details about your app and I will be happy to advise you further!

Best,

Bobby

Try DigitalOcean for free

Click below to sign up and get $200 of credit to try our products over 60 days!

Sign up

Become a contributor for community

Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.

DigitalOcean Documentation

Full documentation for every DigitalOcean product.

Resources for startups and SMBs

The Wave has everything you need to know about building a business, from raising funding to marketing your product.

Get our newsletter

Stay up to date by signing up for DigitalOcean’s Infrastructure as a Newsletter.

New accounts only. By submitting your email you agree to our Privacy Policy

The developer cloud

Scale up as you grow — whether you're running one virtual machine or ten thousand.

Get started for free

Sign up and get $200 in credit for your first 60 days with DigitalOcean.*

*This promotional offer applies to new accounts only.