Skip to content

Instantly share code, notes, and snippets.

Matt Jackson majackson

Block or report user

Report or block majackson

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View migrations.md

Django Migrations without Downtime

Note that in the below instructions, migrations are all run manually and are not an automatic part of the deployment process.

Adding Fields or Tables

Adding a (nullable) field or a new table

  1. Make the model or column addition in your code.
  2. Generate the model-change migrations locally.
  3. Make two separate pull requests, one containing the model change, one containing the newly-generated migrationst. Note that the model-change migration should only contain the model change code, not any supplemental code using the newly-structured model.
@majackson
majackson / migrations.md
Last active Sep 17, 2019
Django migrations without downtime
View migrations.md

Django Migrations without Downtime

The following instructions describe a set of processes allowing you to run Django database migrations against a production database without having to bring the web service down.

Note that in the below instructions, migrations are all run manually at explicit points, and are not an automatic part of the deployment process.

Adding Fields or Tables

Adding a (nullable) field or a new table

  1. Make the model or column addition in your code.
@majackson
majackson / arrayfield_listfilter.py
Created Nov 2, 2015
A reusable list filter for displaying/filtering ArrayFields in the django admin
View arrayfield_listfilter.py
from django.contrib import admin
class ArrayFieldListFilter(admin.SimpleListFilter):
"Admin-filterable field for an ArrayList"
def __init__(self, request, params, model, model_admin):
self._choices = model._meta.get_field(self.parameter_name).base_field.choices
super(ArrayFieldListFilter, self).__init__(request, params, model, model_admin)
@majackson
majackson / jsonlistfile.py
Created Apr 24, 2012
Class providing methods and context manager to efficiently read and write list-based json documents.
View jsonlistfile.py
import json
class JsonListFile(object):
"""Class providing methods and context manager to read and write list-based
json documents.
This class will write out to the file on each append (maybe, os-dependent),
eliminating the need to hold the entire json object in memory before writing
(as is necessary with the plain stdlib json module).
Primitive, but useful."""
@majackson
majackson / add_novalidate.js
Created Mar 5, 2012
Bookmarklet to remove HTML5 validation from all forms on a page
View add_novalidate.js
javascript:fs=document.getElementsByTagName('form'); for (f=0;f<fs.length;f++) { f.setAttribute('novalidate', 'novalidate') }
You can’t perform that action at this time.