<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Renu Bhati</title>
    <description>The latest articles on DEV Community by Renu Bhati (@renubhati).</description>
    <link>https://dev.to/renubhati</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F3339319%2F49aac765-3a74-49e6-9f6f-a74894c56e5c.jpeg</url>
      <title>DEV Community: Renu Bhati</title>
      <link>https://dev.to/renubhati</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/renubhati"/>
    <language>en</language>
    <item>
      <title>How I Cut My Local Development Setup Time by 95% Using Makefile</title>
      <dc:creator>Renu Bhati</dc:creator>
      <pubDate>Wed, 09 Jul 2025 14:55:22 +0000</pubDate>
      <link>https://dev.to/renubhati/how-i-cut-my-local-development-setup-time-by-95-using-makefile-55oc</link>
      <guid>https://dev.to/renubhati/how-i-cut-my-local-development-setup-time-by-95-using-makefile-55oc</guid>
      <description>&lt;p&gt;&lt;em&gt;How one simple file transformed my development workflow from 10 minutes to 30 seconds&lt;/em&gt;&lt;/p&gt;




&lt;p&gt;As a developer, I was constantly typing the same Docker and database commands over and over. Starting PostgreSQL containers, running migrations, creating databases - it was getting repetitive and error-prone.&lt;/p&gt;

&lt;p&gt;Setting up my local development environment was taking forever every time I switched between projects or started fresh. I needed something to make local development setup quick and consistent.&lt;/p&gt;

&lt;p&gt;That's when I discovered I could use Makefiles to automate all these database operations for faster local development. Here's what I learned.&lt;/p&gt;

&lt;h2&gt;
  
  
  What is a Makefile?
&lt;/h2&gt;

&lt;p&gt;A Makefile is a simple text file that contains commands you can run with the &lt;code&gt;make&lt;/code&gt; command. While most people think it's only for compiling C programs, it's actually great for automating any repetitive tasks - including database operations.&lt;/p&gt;

&lt;h2&gt;
  
  
  My Database Makefile for Local Development
&lt;/h2&gt;

&lt;p&gt;Here's the Makefile I created to speed up my local development setup with PostgreSQL:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight make"&gt;&lt;code&gt;&lt;span class="c"&gt;# Default target - shows help when you just run 'make'
&lt;/span&gt;&lt;span class="nv"&gt;.DEFAULT_GOAL&lt;/span&gt; &lt;span class="o"&gt;:=&lt;/span&gt; &lt;span class="nb"&gt;help&lt;/span&gt;

&lt;span class="nl"&gt;help&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt; &lt;span class="c"&gt;##&lt;/span&gt;&lt;span class="nf"&gt; Show all available commands&lt;/span&gt;
    &lt;span class="p"&gt;@&lt;/span&gt;&lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="s2"&gt;"Available commands:"&lt;/span&gt;
    &lt;span class="p"&gt;@&lt;/span&gt;&lt;span class="nb"&gt;grep&lt;/span&gt; &lt;span class="nt"&gt;-E&lt;/span&gt; &lt;span class="s1"&gt;'^[a-zA-Z_-]+:.*?## .*$'&lt;/span&gt; &lt;span class="p"&gt;$(&lt;/span&gt;MAKEFILE_LIST&lt;span class="p"&gt;)&lt;/span&gt; | &lt;span class="nb"&gt;sort&lt;/span&gt; | &lt;span class="nb"&gt;awk&lt;/span&gt; &lt;span class="s1"&gt;'BEGIN {FS = ":.*?## "}; {printf "  %-15s %s\n", $1, $2}'&lt;/span&gt;

&lt;span class="nl"&gt;postgres&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt; &lt;span class="c"&gt;##&lt;/span&gt;&lt;span class="nf"&gt; Start PostgreSQL container&lt;/span&gt;
    docker run &lt;span class="nt"&gt;--name&lt;/span&gt; postgres &lt;span class="nt"&gt;-p&lt;/span&gt; 5432:5432 &lt;span class="nt"&gt;-e&lt;/span&gt; &lt;span class="nv"&gt;POSTGRES_USER&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;root &lt;span class="nt"&gt;-e&lt;/span&gt; &lt;span class="nv"&gt;POSTGRES_PASSWORD&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;secret &lt;span class="nt"&gt;-d&lt;/span&gt; postgres

&lt;span class="nl"&gt;remove-postgres&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt; &lt;span class="c"&gt;##&lt;/span&gt;&lt;span class="nf"&gt; Stop and remove PostgreSQL container&lt;/span&gt;
    docker stop postgres
    docker &lt;span class="nb"&gt;rm &lt;/span&gt;postgres

&lt;span class="nl"&gt;createdb&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt; &lt;span class="c"&gt;##&lt;/span&gt;&lt;span class="nf"&gt; Create database&lt;/span&gt;
    docker &lt;span class="nb"&gt;exec&lt;/span&gt; &lt;span class="nt"&gt;-it&lt;/span&gt; postgres createdb &lt;span class="nt"&gt;--username&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;root &lt;span class="nt"&gt;--owner&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;root simple_bank

&lt;span class="nl"&gt;dropdb&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt; &lt;span class="c"&gt;##&lt;/span&gt;&lt;span class="nf"&gt; Delete database&lt;/span&gt;
    docker &lt;span class="nb"&gt;exec&lt;/span&gt; &lt;span class="nt"&gt;-it&lt;/span&gt; postgres dropdb simple_bank

&lt;span class="nl"&gt;migrateup&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt; &lt;span class="c"&gt;##&lt;/span&gt;&lt;span class="nf"&gt; Run database migrations&lt;/span&gt;
    migrate &lt;span class="nt"&gt;-path&lt;/span&gt; db/migration &lt;span class="nt"&gt;-database&lt;/span&gt; &lt;span class="s2"&gt;"postgresql://root:secret@localhost:5432/simple_bank?sslmode=disable"&lt;/span&gt; up

&lt;span class="nl"&gt;migratedown&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt; &lt;span class="c"&gt;##&lt;/span&gt;&lt;span class="nf"&gt; Rollback database migrations&lt;/span&gt;
    migrate &lt;span class="nt"&gt;-path&lt;/span&gt; db/migration &lt;span class="nt"&gt;-database&lt;/span&gt; &lt;span class="s2"&gt;"postgresql://root:secret@localhost:5432/simple_bank?sslmode=disable"&lt;/span&gt; down

&lt;span class="nl"&gt;.PHONY&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt; &lt;span class="nf"&gt;help postgres remove-postgres createdb dropdb migrateup migratedown&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  How Each Command Works
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Starting PostgreSQL
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;make postgres
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This starts a PostgreSQL container with:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Container name: &lt;code&gt;postgres&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;Port: &lt;code&gt;5432&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;Username: &lt;code&gt;root&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;Password: &lt;code&gt;secret&lt;/code&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Stopping PostgreSQL
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;make remove-postgres
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This stops and removes the PostgreSQL container completely.&lt;/p&gt;

&lt;h3&gt;
  
  
  Creating Database
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;make createdb
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This creates a new database called &lt;code&gt;simple_bank&lt;/code&gt; inside the running PostgreSQL container.&lt;/p&gt;

&lt;h3&gt;
  
  
  Dropping Database
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;make dropdb
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This deletes the &lt;code&gt;simple_bank&lt;/code&gt; database.&lt;/p&gt;

&lt;h3&gt;
  
  
  Running Migrations
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;make migrateup
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This runs all pending database migrations from the &lt;code&gt;db/migration&lt;/code&gt; folder.&lt;/p&gt;

&lt;h3&gt;
  
  
  Rolling Back Migrations
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;make migratedown
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This rolls back the last migration.&lt;/p&gt;

&lt;h2&gt;
  
  
  Why Use Makefile for Local Development?
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Before Makefile (slow setup):&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="c"&gt;# I had to remember and type these long commands every time&lt;/span&gt;
docker run &lt;span class="nt"&gt;--name&lt;/span&gt; postgres &lt;span class="nt"&gt;-p&lt;/span&gt; 5432:5432 &lt;span class="nt"&gt;-e&lt;/span&gt; &lt;span class="nv"&gt;POSTGRES_USER&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;root &lt;span class="nt"&gt;-e&lt;/span&gt; &lt;span class="nv"&gt;POSTGRES_PASSWORD&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;secret &lt;span class="nt"&gt;-d&lt;/span&gt; postgres
docker &lt;span class="nb"&gt;exec&lt;/span&gt; &lt;span class="nt"&gt;-it&lt;/span&gt; postgres createdb &lt;span class="nt"&gt;--username&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;root &lt;span class="nt"&gt;--owner&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;root simple_bank
migrate &lt;span class="nt"&gt;-path&lt;/span&gt; db/migration &lt;span class="nt"&gt;-database&lt;/span&gt; &lt;span class="s2"&gt;"postgresql://root:secret@localhost:5432/simple_bank?sslmode=disable"&lt;/span&gt; up
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;After Makefile (quick setup):&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="c"&gt;# Simple, fast commands for local development&lt;/span&gt;
make postgres
make createdb
make migrateup
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now I can get my local development environment running in seconds instead of minutes!&lt;/p&gt;

&lt;h2&gt;
  
  
  Adding a Help Command
&lt;/h2&gt;

&lt;p&gt;One really useful feature I added is a help command that shows all available commands:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;make &lt;span class="nb"&gt;help&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This displays:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Available commands:
  createdb         Create database
  dropdb           Delete database
  help             Show all available commands
  migratedown      Rollback database migrations
  migrateup        Run database migrations
  postgres         Start PostgreSQL container
  remove-postgres  Stop and remove PostgreSQL container
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You can also just run &lt;code&gt;make&lt;/code&gt; without any command, and it will show the help automatically.&lt;/p&gt;

&lt;p&gt;The help command works by:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Adding &lt;code&gt;## description&lt;/code&gt; after each command&lt;/li&gt;
&lt;li&gt;Using a special help target that parses these descriptions&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Setting &lt;code&gt;.DEFAULT_GOAL := help&lt;/code&gt; so &lt;code&gt;make&lt;/code&gt; alone shows help&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Create a file named &lt;code&gt;Makefile&lt;/code&gt; in your project root&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Copy the commands above and modify them for your project:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Change database name from &lt;code&gt;simple_bank&lt;/code&gt; to your database name&lt;/li&gt;
&lt;li&gt;Update username/password if needed&lt;/li&gt;
&lt;li&gt;Adjust the migration path if different&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Run commands using &lt;code&gt;make &amp;lt;command-name&amp;gt;&lt;/code&gt;&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  Important Notes
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;The indentation in Makefile must be tabs, not spaces&lt;/li&gt;
&lt;li&gt;The &lt;code&gt;.PHONY&lt;/code&gt; line tells Make that these aren't file names&lt;/li&gt;
&lt;li&gt;Make sure Docker is running before using these commands&lt;/li&gt;
&lt;li&gt;Install &lt;code&gt;migrate&lt;/code&gt; tool if you want to use migration commands&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Common Local Development Workflow
&lt;/h2&gt;

&lt;p&gt;Here's how I typically use these commands to set up my local development environment:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="c"&gt;# Quick local setup when starting work&lt;/span&gt;
make postgres
make createdb
make migrateup

&lt;span class="c"&gt;# Now I can start coding immediately!&lt;/span&gt;

&lt;span class="c"&gt;# When switching projects or need fresh database&lt;/span&gt;
make remove-postgres
make postgres
make createdb
make migrateup

&lt;span class="c"&gt;# At end of day (optional - frees up resources)&lt;/span&gt;
make remove-postgres
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This workflow gets me from zero to coding in under 30 seconds!&lt;/p&gt;

&lt;h2&gt;
  
  
  Benefits for Local Development
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Super fast setup&lt;/strong&gt; - From zero to coding in 30 seconds&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;No more typos&lt;/strong&gt; - I don't have to type long Docker commands&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Consistency&lt;/strong&gt; - Same setup works on any machine&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Easy project switching&lt;/strong&gt; - Quick tear down and setup&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Team onboarding&lt;/strong&gt; - New developers can start immediately&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;Using Makefiles for local development database operations has been a game-changer for my workflow. Instead of memorizing complex Docker and migration commands, I just run simple &lt;code&gt;make&lt;/code&gt; commands and get my development environment ready instantly.&lt;/p&gt;

&lt;p&gt;If you're tired of slow local development setup and want to start coding faster, give this approach a try. Start with basic commands like the ones I shared, and you'll quickly see how much time it saves in your daily development routine.&lt;/p&gt;




&lt;h2&gt;
  
  
  Quick Reference
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;make postgres      &lt;span class="c"&gt;# Start PostgreSQL container&lt;/span&gt;
make remove-postgres &lt;span class="c"&gt;# Stop and remove container&lt;/span&gt;
make createdb      &lt;span class="c"&gt;# Create database&lt;/span&gt;
make dropdb        &lt;span class="c"&gt;# Delete database&lt;/span&gt;
make migrateup     &lt;span class="c"&gt;# Run migrations&lt;/span&gt;
make migratedown   &lt;span class="c"&gt;# Rollback migrations&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



</description>
      <category>go</category>
      <category>webdev</category>
      <category>productivity</category>
      <category>postgres</category>
    </item>
  </channel>
</rss>
