-
Notifications
You must be signed in to change notification settings - Fork 985
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #15 from dstufft/database-migrations
Database migrations
- Loading branch information
Showing
7 changed files
with
149 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
-- Make sure there is a value in every last_login field | ||
UPDATE users SET last_login = '-infinity' WHERE last_login IS NULL; | ||
|
||
-- Copy over the users from users to accounts_user | ||
INSERT INTO accounts_user | ||
(username, password, last_login, is_active, is_staff, is_superuser, name, date_joined) | ||
SELECT name, password, last_login, TRUE, FALSE, FALSE, '', '-infinity' | ||
FROM users; | ||
|
||
-- Update the password to use the Django style passwords | ||
UPDATE accounts_user SET password = 'bcrypt$' || password WHERE password LIKE '$2a$%'; | ||
|
||
-- For each user with an email, create an accounts_email row | ||
INSERT INTO accounts_email | ||
(user_id, email, "primary", verified) | ||
SELECT DISTINCT ON (users.email) | ||
accounts_user.id, users.email, TRUE, TRUE | ||
FROM users, accounts_user | ||
WHERE users.name = accounts_user.username AND users.email IS NOT NULL; | ||
|
||
-- Set every user with the Admin role to a staff member and superadmin | ||
UPDATE accounts_user | ||
SET | ||
is_staff = TRUE, is_superuser = TRUE | ||
FROM roles | ||
WHERE roles.role_name = 'Admin' AND accounts_user.username = roles.user_name; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,6 +22,7 @@ | |
"Django", | ||
"django-braces", | ||
"django-configurations>=0.2.1", | ||
"South", | ||
], | ||
extras_require={ | ||
"tests": [ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,113 @@ | ||
# -*- coding: utf-8 -*- | ||
import datetime | ||
from south.db import db | ||
from south.v2 import SchemaMigration | ||
from django.db import models | ||
|
||
|
||
class Migration(SchemaMigration): | ||
|
||
def forwards(self, orm): | ||
# Adding model 'User' | ||
db.create_table('accounts_user', ( | ||
('id', self.gf('django.db.models.fields.AutoField')(primary_key=True)), | ||
('password', self.gf('django.db.models.fields.CharField')(max_length=128)), | ||
('last_login', self.gf('django.db.models.fields.DateTimeField')(default=datetime.datetime.now)), | ||
('is_superuser', self.gf('django.db.models.fields.BooleanField')(default=False)), | ||
('username', self.gf('django.db.models.fields.CharField')(unique=True, max_length=50)), | ||
('name', self.gf('django.db.models.fields.CharField')(blank=True, max_length=100)), | ||
('is_staff', self.gf('django.db.models.fields.BooleanField')(default=False)), | ||
('is_active', self.gf('django.db.models.fields.BooleanField')(default=True)), | ||
('date_joined', self.gf('django.db.models.fields.DateTimeField')(default=datetime.datetime.now)), | ||
)) | ||
db.send_create_signal('accounts', ['User']) | ||
|
||
# Adding M2M table for field groups on 'User' | ||
m2m_table_name = db.shorten_name('accounts_user_groups') | ||
db.create_table(m2m_table_name, ( | ||
('id', models.AutoField(verbose_name='ID', primary_key=True, auto_created=True)), | ||
('user', models.ForeignKey(orm['accounts.user'], null=False)), | ||
('group', models.ForeignKey(orm['auth.group'], null=False)) | ||
)) | ||
db.create_unique(m2m_table_name, ['user_id', 'group_id']) | ||
|
||
# Adding M2M table for field user_permissions on 'User' | ||
m2m_table_name = db.shorten_name('accounts_user_user_permissions') | ||
db.create_table(m2m_table_name, ( | ||
('id', models.AutoField(verbose_name='ID', primary_key=True, auto_created=True)), | ||
('user', models.ForeignKey(orm['accounts.user'], null=False)), | ||
('permission', models.ForeignKey(orm['auth.permission'], null=False)) | ||
)) | ||
db.create_unique(m2m_table_name, ['user_id', 'permission_id']) | ||
|
||
# Adding model 'Email' | ||
db.create_table('accounts_email', ( | ||
('id', self.gf('django.db.models.fields.AutoField')(primary_key=True)), | ||
('user', self.gf('django.db.models.fields.related.ForeignKey')(related_name='emails', to=orm['accounts.User'], on_delete=models.DO_NOTHING)), | ||
('email', self.gf('django.db.models.fields.EmailField')(unique=True, max_length=254)), | ||
('primary', self.gf('django.db.models.fields.BooleanField')(default=False)), | ||
('verified', self.gf('django.db.models.fields.BooleanField')(default=False)), | ||
)) | ||
db.send_create_signal('accounts', ['Email']) | ||
|
||
|
||
def backwards(self, orm): | ||
# Deleting model 'User' | ||
db.delete_table('accounts_user') | ||
|
||
# Removing M2M table for field groups on 'User' | ||
db.delete_table(db.shorten_name('accounts_user_groups')) | ||
|
||
# Removing M2M table for field user_permissions on 'User' | ||
db.delete_table(db.shorten_name('accounts_user_user_permissions')) | ||
|
||
# Deleting model 'Email' | ||
db.delete_table('accounts_email') | ||
|
||
|
||
models = { | ||
'accounts.email': { | ||
'Meta': {'object_name': 'Email'}, | ||
'email': ('django.db.models.fields.EmailField', [], {'unique': 'True', 'max_length': '254'}), | ||
'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), | ||
'primary': ('django.db.models.fields.BooleanField', [], {'default': 'False'}), | ||
'user': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'emails'", 'to': "orm['accounts.User']", 'on_delete': 'models.DO_NOTHING'}), | ||
'verified': ('django.db.models.fields.BooleanField', [], {'default': 'False'}) | ||
}, | ||
'accounts.user': { | ||
'Meta': {'object_name': 'User'}, | ||
'date_joined': ('django.db.models.fields.DateTimeField', [], {'default': 'datetime.datetime.now'}), | ||
'groups': ('django.db.models.fields.related.ManyToManyField', [], {'to': "orm['auth.Group']", 'blank': 'True', 'symmetrical': 'False'}), | ||
'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), | ||
'is_active': ('django.db.models.fields.BooleanField', [], {'default': 'True'}), | ||
'is_staff': ('django.db.models.fields.BooleanField', [], {'default': 'False'}), | ||
'is_superuser': ('django.db.models.fields.BooleanField', [], {'default': 'False'}), | ||
'last_login': ('django.db.models.fields.DateTimeField', [], {'default': 'datetime.datetime.now'}), | ||
'name': ('django.db.models.fields.CharField', [], {'blank': 'True', 'max_length': '100'}), | ||
'password': ('django.db.models.fields.CharField', [], {'max_length': '128'}), | ||
'user_permissions': ('django.db.models.fields.related.ManyToManyField', [], {'to': "orm['auth.Permission']", 'blank': 'True', 'symmetrical': 'False'}), | ||
'username': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '50'}) | ||
}, | ||
'auth.group': { | ||
'Meta': {'object_name': 'Group'}, | ||
'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), | ||
'name': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '80'}), | ||
'permissions': ('django.db.models.fields.related.ManyToManyField', [], {'to': "orm['auth.Permission']", 'blank': 'True', 'symmetrical': 'False'}) | ||
}, | ||
'auth.permission': { | ||
'Meta': {'ordering': "('content_type__app_label', 'content_type__model', 'codename')", 'unique_together': "(('content_type', 'codename'),)", 'object_name': 'Permission'}, | ||
'codename': ('django.db.models.fields.CharField', [], {'max_length': '100'}), | ||
'content_type': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['contenttypes.ContentType']"}), | ||
'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), | ||
'name': ('django.db.models.fields.CharField', [], {'max_length': '50'}) | ||
}, | ||
'contenttypes.contenttype': { | ||
'Meta': {'db_table': "'django_content_type'", 'ordering': "('name',)", 'unique_together': "(('app_label', 'model'),)", 'object_name': 'ContentType'}, | ||
'app_label': ('django.db.models.fields.CharField', [], {'max_length': '100'}), | ||
'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), | ||
'model': ('django.db.models.fields.CharField', [], {'max_length': '100'}), | ||
'name': ('django.db.models.fields.CharField', [], {'max_length': '100'}) | ||
} | ||
} | ||
|
||
complete_apps = ['accounts'] |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters