Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Database migrations #15

Merged
merged 2 commits into from
May 11, 2013
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions contrib/convert_pypi.sql
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;
3 changes: 3 additions & 0 deletions coverage.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,6 @@ omit =
warehouse/__main__.py
warehouse/conf.py
warehouse/wsgi.py

# Migrations don't make sense to include in coverage
warehouse/accounts/migrations/*
3 changes: 3 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,8 @@ invoke
# Install Django (we are using an unreleased version)
-e git+https://github.com/django/django.git#egg=Django-dev

# Install South (Python 3.x support is only in trunk)
-e hg+https://bitbucket.org/andrewgodwin/south#egg=South-dev

# Install Warehouse (and it's dependencies)
-e .[tests]
1 change: 1 addition & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
"Django",
"django-braces",
"django-configurations>=0.2.1",
"South",
],
extras_require={
"tests": [
Expand Down
113 changes: 113 additions & 0 deletions warehouse/accounts/migrations/0001_initial.py
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.
3 changes: 3 additions & 0 deletions warehouse/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ class Settings(BaseSettings):
"django.contrib.messages",
"django.contrib.staticfiles",

# External Applications
"south",

# Warehouse Apps
"warehouse",
"warehouse.accounts",
Expand Down