diff --git a/README.md b/README.md index 250aee6..ee9bd8b 100644 --- a/README.md +++ b/README.md @@ -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. diff --git a/dbfilestorage/migrations/0007_auto_20170206_1940.py b/dbfilestorage/migrations/0007_auto_20170206_1940.py new file mode 100644 index 0000000..1df1f51 --- /dev/null +++ b/dbfilestorage/migrations/0007_auto_20170206_1940.py @@ -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), + ) + ] diff --git a/dbfilestorage/migrations/0008_auto_20170206_1945.py b/dbfilestorage/migrations/0008_auto_20170206_1945.py new file mode 100644 index 0000000..7aa73ed --- /dev/null +++ b/dbfilestorage/migrations/0008_auto_20170206_1945.py @@ -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) + ] diff --git a/dbfilestorage/migrations/0009_auto_20170206_1954.py b/dbfilestorage/migrations/0009_auto_20170206_1954.py new file mode 100644 index 0000000..7dddae9 --- /dev/null +++ b/dbfilestorage/migrations/0009_auto_20170206_1954.py @@ -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), + ), + ] diff --git a/dbfilestorage/migrations/0010_auto_20170206_1954.py b/dbfilestorage/migrations/0010_auto_20170206_1954.py new file mode 100644 index 0000000..383d5f5 --- /dev/null +++ b/dbfilestorage/migrations/0010_auto_20170206_1954.py @@ -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', + ), + ] diff --git a/dbfilestorage/migrations/0011_auto_20170206_1956.py b/dbfilestorage/migrations/0011_auto_20170206_1956.py new file mode 100644 index 0000000..3d21f12 --- /dev/null +++ b/dbfilestorage/migrations/0011_auto_20170206_1956.py @@ -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), + ), + ] diff --git a/dbfilestorage/migrations/0012_auto_20170206_2004.py b/dbfilestorage/migrations/0012_auto_20170206_2004.py new file mode 100644 index 0000000..19101c8 --- /dev/null +++ b/dbfilestorage/migrations/0012_auto_20170206_2004.py @@ -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'), + ), + ] diff --git a/dbfilestorage/models.py b/dbfilestorage/models.py index cd2d56e..a1d076a 100644 --- a/dbfilestorage/models.py +++ b/dbfilestorage/models.py @@ -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) diff --git a/dbfilestorage/storage.py b/dbfilestorage/storage.py index 0800245..e8bac0e 100644 --- a/dbfilestorage/storage.py +++ b/dbfilestorage/storage.py @@ -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() diff --git a/docs/conf.py b/docs/conf.py index dbc95f0..96c57d8 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -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 diff --git a/setup.py b/setup.py index d9f017e..c593f51 100644 --- a/setup.py +++ b/setup.py @@ -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",