Skip to content

Instantly share code, notes, and snippets.

View delacruzjames's full-sized avatar
🏠
Working from home

James Dela Cruz delacruzjames

🏠
Working from home
View GitHub Profile
@delacruzjames
delacruzjames / index.md
Created June 13, 2020 15:26 — forked from rstacruz/index.md
Rails models cheatsheet

Rails Models

Generating models

$ rails g model User

Associations

belongs_to

has_one

React File Structure
@delacruzjames
delacruzjames / migrate.py
Created March 15, 2022 07:29 — forked from jmuhlich/migrate.py
Alembic migration to rename primary and foreign key constraints along with a table rename
from alembic import op
from alembic.operations.ops import CreatePrimaryKeyOp, CreateForeignKeyOp
import sqlalchemy as sa
def upgrade():
conn = op.get_bind()
ctx = op.get_context()
existing_metadata = sa.schema.MetaData()
target_metadata = ctx.opts['target_metadata']
@delacruzjames
delacruzjames / change_primary_key.md
Created March 16, 2022 06:35 — forked from scaryguy/change_primary_key.md
How to change PRIMARY KEY of an existing PostgreSQL table?
-- Firstly, remove PRIMARY KEY attribute of former PRIMARY KEY
ALTER TABLE <table_name> DROP CONSTRAINT <table_name>_pkey;
-- Then change column name of  your PRIMARY KEY and PRIMARY KEY candidates properly.
ALTER TABLE <table_name> RENAME COLUMN <primary_key_candidate> TO id;
@delacruzjames
delacruzjames / app.DockerFile
Created April 19, 2023 09:44 — forked from satendra02/app.DockerFile
docker+rails+puma+nginx+postgres (Production ready)
FROM ruby:2.3.1
# Install dependencies
RUN apt-get update -qq && apt-get install -y build-essential libpq-dev nodejs
# Set an environment variable where the Rails app is installed to inside of Docker image:
ENV RAILS_ROOT /var/www/app_name
RUN mkdir -p $RAILS_ROOT
# Set working directory, where the commands will be ran: