Change pk (#35)

* add new primary_key field.

* Add new field, populate data, change to being pk, change name, double length of name field, and set it to unique

* change version, and add new migration

* bump down the size, 767/4 = 191

* update readme

* remove models.py comment
This commit is contained in:
Tyrel Souza 2017-02-06 15:31:40 -05:00 committed by GitHub
parent c99491c61c
commit 8f811db7c8
11 changed files with 133 additions and 7 deletions

View File

@ -51,6 +51,7 @@ I will sign everything with 0x769A1BC78A2DDEE2
## CHANGELOG
- 2017-02-06 [Tyrel Souza] Set primary key to `id` not `name`, this involves a lot of migrations, so I've kept them in multiple files
- 2017-01-27 [Tyrel Souza] Get rid of filehash
- 2017-01-26 [Tyrel Souza] Check filehash and filename, not just hash when checking if it needs to be saved.
- 2017-01-25 [Tyrel Souza] Keeping Filename on upload.

View File

@ -0,0 +1,20 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.10.4 on 2017-02-06 19:40
from __future__ import unicode_literals
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('dbfilestorage', '0006_remove_dbfile_filehash'),
]
operations = [
migrations.AddField(
model_name='dbfile',
name='primary_key',
field=models.IntegerField(null=True),
)
]

View File

@ -0,0 +1,23 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.10.4 on 2017-02-06 19:45
from __future__ import unicode_literals
from django.db import migrations
def _fix_pk(apps, schema_editor):
""" Set the primary_key to be a series """
DBFile = apps.get_model("dbfilestorage", "DBFile")
for idx, dbf in enumerate(DBFile.objects.all()):
dbf.primary_key = idx+1
dbf.save()
class Migration(migrations.Migration):
dependencies = [
('dbfilestorage', '0007_auto_20170206_1940'),
]
operations = [
migrations.RunPython(_fix_pk)
]

View File

@ -0,0 +1,25 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.10.4 on 2017-02-06 19:54
from __future__ import unicode_literals
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('dbfilestorage', '0008_auto_20170206_1945'),
]
operations = [
migrations.AlterField(
model_name='dbfile',
name='name',
field=models.CharField(max_length=100),
),
migrations.AlterField(
model_name='dbfile',
name='primary_key',
field=models.IntegerField(primary_key=True, serialize=False),
),
]

View File

@ -0,0 +1,20 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.10.4 on 2017-02-06 19:54
from __future__ import unicode_literals
from django.db import migrations
class Migration(migrations.Migration):
dependencies = [
('dbfilestorage', '0009_auto_20170206_1954'),
]
operations = [
migrations.RenameField(
model_name='dbfile',
old_name='primary_key',
new_name='id',
),
]

View File

@ -0,0 +1,20 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.10.4 on 2017-02-06 19:56
from __future__ import unicode_literals
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('dbfilestorage', '0010_auto_20170206_1954'),
]
operations = [
migrations.AlterField(
model_name='dbfile',
name='name',
field=models.CharField(max_length=190, unique=True),
),
]

View File

@ -0,0 +1,20 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.10.4 on 2017-02-06 20:04
from __future__ import unicode_literals
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('dbfilestorage', '0011_auto_20170206_1956'),
]
operations = [
migrations.AlterField(
model_name='dbfile',
name='id',
field=models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID'),
),
]

View File

@ -4,10 +4,7 @@ from django.db import models
class DBFile(models.Model):
""" Model to store and access uploaded files """
# This is kept as `name` and not something like `md5` because the file
# operations pass around `name` as the identifier, so it's kept the same
# to make sense.
name = models.CharField(max_length=100, primary_key=True)
name = models.CharField(max_length=190, unique=True)
# file data
content_type = models.CharField(max_length=100)

View File

@ -69,7 +69,7 @@ class DBFileStorage(Storage):
assert name, "The name argument is not allowed to be empty."
# name is the Pk, so it will be unique, deleting on the QS so
# that it fails silently if the file doesn't exist.
DBFile.objects.filter(pk=name).delete()
DBFile.objects.filter(name=name).delete()
def exists(self, name):
return DBFile.objects.filter(name=name).exists()

View File

@ -54,7 +54,7 @@ author = u'Tyrel Souza'
# built documents.
#
# The short X.Y version.
version = u'0.6.0'
version = u'0.8.0'
# The full version, including alpha/beta/rc tags.
release = version

View File

@ -24,7 +24,7 @@ class CleanCommand(Command):
setup(
name="django-dbfilestorage",
version="0.6.0",
version="0.8.0",
description="Database backed file storage for testing.",
long_description="Database backed file storage for testing. Stores files as base64 encoded textfields.",
author="Tyrel Souza",