Skip to content

Instantly share code, notes, and snippets.

View bharathvaj-ganesan's full-sized avatar
🏠
Working from home

Bharathvaj bharathvaj-ganesan

🏠
Working from home
View GitHub Profile

You can configure Alembic to run migrations on two separate PostgreSQL databases in a single alembic upgrade head command by modifying the env.py script. Here's the approach:

  1. Modify env.py to Manage Multiple Engines:

    • Create two separate SQLAlchemy engines (one for each database) inside the env.py script.
    • Ensure that migrations are applied to both databases.
  2. Use run_migrations_online for Both Databases:

    • Instead of a single engine, define and use two engines.
    • Use context.run_migrations() for each engine.

To follow best practices for running Alembic migrations on two separate PostgreSQL databases while using SQLModel, you should:

  1. Assign Models to Specific Databases: Define separate metadata objects to distinguish models belonging to each database.
  2. Use Separate Migration Folders: Store migration scripts in distinct directories to avoid conflicts and keep each database's schema changes independent.
  3. Modify env.py to Handle Multiple Databases: Configure Alembic to run migrations sequentially for both databases by looping through their configurations and applying changes to the correct metadata.
  4. Ensure Autogeneration Works Properly: Implement logic in env.py to apply --autogenerate migrations to the correct metadata.
  5. Use Async and Sync Engines Correctly: Handle async database connections properly in the Alembic migration flow.

I'll prepare a detailed setup with env.py modifications, migration folder structures, and best practices to ensure Alembic knows which models

@bharathvaj-ganesan
bharathvaj-ganesan / publish.yml
Created April 20, 2025 12:46
Publish npm package as AWS Codeartifact using Github Action Workflow.
name: Publish NPM Package
on:
workflow_dispatch:
permissions:
id-token: write
contents: read
env:
CODEARTIFACT_DOMAIN: <your-codeartifact-domain>
const colorPalettes = [['#152A3B', '#0D809C', '#F5C03E', '#D63826', '#EBEBD6'],
['#0F4155', '#5399A1', '#8CA96B', '#CB5548', '#E7E6F5'],
['#E8614F', '#F3F2DB', '#79C3A7', '#668065', '#4B3331'],
['#DBE5EC', '#336B87', '#2A3132', '#E94D35', '#EFAC55']];
let num = 10;
let colorThemeIndex = 2;
let queueNumber = [0, 1, 2, 3, 4];
let currentPalette, tileLen;
function draw() {
let size = 500;
function setup() {
if (windowWidth < size) {
size = windowWidth; // p5.js property containing window width
}
createCanvas(size, size); // Creates a new canvas of given size
background(25); // adds color to canvas background
angleMode(DEGREES); // sets p5.js anglemode to degrees
noLoop(); // stop the draw function from executing continuously
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>JS Bin</title>
</head>
<body>
<script id="jsbin-javascript">
// events.js
const EventEmitter = require('eventemitter3');
const emitter = new EventEmitter();
function subscribe(req, res) {
res.writeHead(200, {
'Content-Type': 'text/event-stream',
'Cache-Control': 'no-cache',
Connection: 'keep-alive'
const evtSource = new EventSource('/events');
evtSource.addEventListener('event', function(evt) {
const data = JSON.parse(evt.data);
// Use data here
},false);
const express = require('express');
const events = require('./events');
const path = require('path');
const app = express();
const port = process.env.PORT || 5001;
const expressWs = require('express-ws')(app);
$(function () {
// if user is running mozilla then use it's built-in WebSocket
window.WebSocket = window.WebSocket || window.MozWebSocket;
const connection = new WebSocket('ws://localhost:8080/githubEvents');
connection.onopen = function () {
// connection is opened and ready to use
};