Skip to content

toonshi/mikeblogs

Repository files navigation

MikeBlogs

A simple blog project built with Django and Tailwind CSS.

Features

  • Blog posts with images and captions
  • Author profiles
  • Contact form
  • User authentication

Database

This project uses two different databases depending on the environment:

Environment Database Location
Development (local) SQLite db.sqlite3 in the project root
Production (Render) PostgreSQL Managed by Render, configured via DATABASE_URL env var

Is the database empty?

No. The local db.sqlite3 file is included in the repository and already contains sample/seed data:

Table Records
blog_post 4 posts
auth_user 2 users
blog_authorprofile 2 profiles
blog_tag 1 tag
blog_message 1 contact message

You can run python manage.py migrate followed by python manage.py runserver and the blog will already have content without any manual data entry.

The production PostgreSQL database starts empty after deployment. Use the Data Migration steps in the Deployment section to copy data from the local SQLite database into production.

Getting Started

These instructions will get you a copy of the project up and running on your local machine for development and testing purposes.

Prerequisites

  • Python 3.12
  • Node.js and npm

Installation

  1. Clone the repository:

    git clone https://github.com/toonshi/mikeblogs.git
    cd mikeblogs
  2. Create and activate a virtual environment:

    python3 -m venv venv
    source venv/bin/activate
  3. Install Python dependencies:

    pip install -r requirements.txt
  4. Install Node.js dependencies:

    npm install
  5. Build frontend assets:

    npm run build
  6. Run database migrations:

    python manage.py migrate
  7. Run the development server:

    python manage.py runserver

Deployment

This project is configured for deployment on Render.

  • The build.sh script handles the build process.
  • The Procfile specifies the command to run the application.
  • The application is configured to use a PostgreSQL database in production.

Is it wired right?

Yes. The render.yaml blueprint is pre-configured to create and connect to the PostgreSQL database automatically:

render.yaml setting Value Purpose
databases[0].name fragile_thoughts Render service name for the database
databases[0].databaseName fragile_thoughts Actual PostgreSQL database name
databases[0].user fragile_thoughts_user PostgreSQL username
envVars[DATABASE_URL].fromDatabase.name fragile_thoughts Links the web service to the database

When deployed via Render blueprint, the DATABASE_URL environment variable is automatically injected from the database's internal connection string — no manual copy-paste of credentials is needed.

In lost/settings.py, when the RENDER environment variable is present, the app reads DATABASE_URL and configures Django to use PostgreSQL with SSL. On all other environments (local development) it falls back to SQLite.

Free-Tier Database Expiry & Reconnection

Render's free PostgreSQL databases expire after 90 days. When this happens:

  1. The expired database is deleted from Render.
  2. Re-deploy the Render blueprint (render.yaml) — Render will create a new fragile_thoughts database and automatically update DATABASE_URL on the web service.
  3. Run migrations via the Render shell:
    python manage.py migrate
  4. Optionally re-load seed data (see Data Migration below).

Note: You do not need to hard-code any connection strings. The fromDatabase: connectionString in render.yaml keeps everything in sync automatically.

Connecting to the Database Locally

To develop against the Render production database from your local machine, copy .env.example to .env and set DATABASE_URL to the External Database URL shown in the Render dashboard for the fragile_thoughts database (it ends in .oregon-postgres.render.com). Make sure to append ?sslmode=require:

DATABASE_URL=postgresql://<user>:<password>@<hostname>.oregon-postgres.render.com/<dbname>?sslmode=require

Data Migration

To migrate data from a local SQLite database to a production PostgreSQL database, follow these steps:

  1. Dump data from local SQLite database:

    python manage.py dumpdata --natural-foreign --natural-primary -e contenttypes -e auth.permission -e admin > datadump.json
  2. Load data into production database: In the Render shell (or your production environment's shell), run the following command:

    python manage.py loaddata datadump.json

Built With

About

My blogging site where I shitpost & sometimes share useful thoughts

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors