|
@@ -1,4 +1,4 @@
|
1
|
|
-"""all files only on disk
|
|
1
|
+"""all files only on disk.
|
2
|
2
|
|
3
|
3
|
Revision ID: f3852e1349c4
|
4
|
4
|
Revises: 913efdf409e5
|
|
@@ -8,10 +8,11 @@ Create Date: 2017-07-24 17:15:54.278141
|
8
|
8
|
|
9
|
9
|
from alembic import context
|
10
|
10
|
from alembic import op
|
|
11
|
+
|
11
|
12
|
from depot.fields.sqlalchemy import UploadedFileField
|
12
|
13
|
from depot.manager import DepotManager
|
|
14
|
+
|
13
|
15
|
import sqlalchemy as sa
|
14
|
|
-from sqlalchemy.sql.expression import func
|
15
|
16
|
|
16
|
17
|
# revision identifiers, used by Alembic.
|
17
|
18
|
revision = 'f3852e1349c4'
|
|
@@ -33,9 +34,6 @@ revision_helper = sa.Table(
|
33
|
34
|
'content_revisions',
|
34
|
35
|
sa.MetaData(),
|
35
|
36
|
sa.Column('revision_id', sa.Integer, primary_key=True),
|
36
|
|
- sa.Column('label', sa.String(1024), nullable=False),
|
37
|
|
- sa.Column('file_extension', sa.String(255), nullable=False),
|
38
|
|
- sa.Column('file_mimetype', sa.String(255), nullable=False),
|
39
|
37
|
sa.Column('file_content', sa.LargeBinary),
|
40
|
38
|
sa.Column('depot_file', UploadedFileField, nullable=True),
|
41
|
39
|
sa.Column('type', sa.String(32), nullable=False),
|
|
@@ -43,13 +41,13 @@ revision_helper = sa.Table(
|
43
|
41
|
|
44
|
42
|
|
45
|
43
|
def upgrade():
|
46
|
|
- """Drops the file content from revision."""
|
|
44
|
+ """Drop the file content from revision."""
|
47
|
45
|
with op.batch_alter_table('content_revisions') as batch_op:
|
48
|
46
|
batch_op.drop_column('file_content')
|
49
|
47
|
|
50
|
48
|
|
51
|
49
|
def downgrade():
|
52
|
|
- """Adds the file content in revision."""
|
|
50
|
+ """Add the file content in revision."""
|
53
|
51
|
with op.batch_alter_table('content_revisions') as batch_op:
|
54
|
52
|
batch_op.add_column(sa.Column('file_content', sa.LargeBinary))
|
55
|
53
|
|
|
@@ -58,11 +56,10 @@ def downgrade():
|
58
|
56
|
connection = op.get_bind()
|
59
|
57
|
select_query = revision_helper.select() \
|
60
|
58
|
.where(revision_helper.c.type == 'file') \
|
61
|
|
- .where(revision_helper.c.depot_file.isnot(None)) \
|
62
|
|
- .where(func.length(revision_helper.c.depot_file) > 0)
|
|
59
|
+ .where(revision_helper.c.depot_file.isnot(None))
|
63
|
60
|
files = connection.execute(select_query).fetchall()
|
64
|
61
|
for file in files:
|
65
|
|
- depot_file_content = depot.get(file.depot_file)
|
|
62
|
+ depot_file_content = depot.get(file.depot_file).read()
|
66
|
63
|
update_query = revision_helper.update() \
|
67
|
64
|
.where(revision_helper.c.revision_id == file.revision_id) \
|
68
|
65
|
.values(file_content=depot_file_content)
|