Browse Source

Drop tracim v1 migration revs

Guénaël Muller 7 years ago
parent
commit
5dec2557c8

+ 0 - 77
tracim/migration/versions/15305f71bfda_fill_content_file_extension_column.py View File

@@ -1,77 +0,0 @@
1
-"""fill content file_extension column
2
-
3
-Revision ID: 15305f71bfda
4
-Revises: e31ddc009b37
5
-Create Date: 2016-11-25 10:50:01.874820
6
-
7
-"""
8
-
9
-# revision identifiers, used by Alembic.
10
-import os
11
-
12
-revision = '15305f71bfda'
13
-down_revision = 'e31ddc009b37'
14
-
15
-from alembic import op
16
-import sqlalchemy as sa
17
-
18
-
19
-content_revision_helper = sa.Table(
20
-    'content_revisions',
21
-    sa.MetaData(),
22
-    sa.Column('revision_id', sa.Integer, primary_key=True),
23
-    sa.Column('content_id', sa.ForeignKey(u'content.id'), nullable=False),
24
-    sa.Column('owner_id', sa.ForeignKey(u'users.user_id'), index=True),
25
-    sa.Column('label', sa.String(1024), nullable=False),
26
-    sa.Column('description', sa.Text, nullable=False),
27
-    sa.Column('file_name', sa.String(255), nullable=False),
28
-    sa.Column('file_extension', sa.String(255), nullable=False),
29
-    sa.Column('file_mimetype', sa.String(255), nullable=False),
30
-    sa.Column('file_content', sa.LargeBinary),
31
-    sa.Column('properties', sa.Text, nullable=False),
32
-    sa.Column('type', sa.String(32), nullable=False),
33
-    sa.Column('status', sa.String(32), nullable=False),
34
-    sa.Column('created', sa.DateTime, nullable=False),
35
-    sa.Column('updated', sa.DateTime, nullable=False),
36
-    sa.Column('is_deleted', sa.Boolean, nullable=False),
37
-    sa.Column('is_archived', sa.Boolean, nullable=False),
38
-    sa.Column('is_temporary', sa.Boolean, nullable=False),
39
-    sa.Column('revision_type', sa.String(32), nullable=False),
40
-    sa.Column('workspace_id', sa.ForeignKey(u'workspaces.workspace_id')),
41
-    sa.Column('parent_id', sa.ForeignKey(u'content.id'), index=True),
42
-)
43
-
44
-
45
-def upgrade():
46
-    connection = op.get_bind()
47
-
48
-    for content_revision in connection.execute(
49
-            content_revision_helper.select()
50
-    ):
51
-        # On work with FILE
52
-        if content_revision.type == 'file':
53
-            file_name, file_extension = \
54
-                os.path.splitext(content_revision.file_name)
55
-
56
-            # Don't touch label if already set
57
-            if content_revision.label:
58
-                new_label = content_revision.label
59
-            # Label will be file name without extension
60
-            else:
61
-                new_label = file_name
62
-
63
-            # Update record
64
-            connection.execute(
65
-                content_revision_helper.update()
66
-                .where(
67
-                    content_revision_helper.c.revision_id ==
68
-                    content_revision.revision_id
69
-                ).values(
70
-                    label=new_label,
71
-                    file_extension=file_extension,
72
-                )
73
-            )
74
-
75
-
76
-def downgrade():
77
-    pass

+ 1 - 1
tracim/migration/versions/2b4043fa2502_remove_webdav_right_digest_response_.py View File

@@ -8,7 +8,7 @@ Create Date: 2018-03-13 14:41:38.590375
8 8
 
9 9
 # revision identifiers, used by Alembic.
10 10
 revision = '2b4043fa2502'
11
-down_revision = 'f3852e1349c4'
11
+down_revision = None
12 12
 
13 13
 from alembic import op
14 14
 from sqlalchemy import Column, Unicode

+ 0 - 26
tracim/migration/versions/2cd20ff3d23a_user_timezone.py View File

@@ -1,26 +0,0 @@
1
-"""user_timezone
2
-
3
-Revision ID: 2cd20ff3d23a
4
-Revises: b4b8d57b54e5
5
-Create Date: 2016-11-08 11:32:00.903232
6
-
7
-"""
8
-
9
-# revision identifiers, used by Alembic.
10
-revision = '2cd20ff3d23a'
11
-down_revision = 'b4b8d57b54e5'
12
-
13
-from alembic import op
14
-import sqlalchemy as sa
15
-
16
-
17
-def upgrade():
18
-    ### commands auto generated by Alembic - please adjust! ###
19
-    op.add_column('users', sa.Column('timezone', sa.Unicode(length=255), server_default='', nullable=False))
20
-    ### end Alembic commands ###
21
-
22
-
23
-def downgrade():
24
-    ### commands auto generated by Alembic - please adjust! ###
25
-    op.drop_column('users', 'timezone')
26
-    ### end Alembic commands ###

+ 0 - 28
tracim/migration/versions/43a323cc661_add_read_not_read_content_status.py View File

@@ -1,28 +0,0 @@
1
-"""add read/not read content status
2
-
3
-Revision ID: 43a323cc661
4
-Revises: None
5
-Create Date: 2015-08-26 11:23:03.466554
6
-
7
-"""
8
-
9
-# revision identifiers, used by Alembic.
10
-revision = '43a323cc661'
11
-down_revision = None
12
-
13
-from alembic import op
14
-import sqlalchemy as sa
15
-
16
-
17
-def upgrade():
18
-    op.create_table(
19
-        'revision_read_status',
20
-        sa.Column('revision_id', sa.Integer, sa.ForeignKey('content_revisions.revision_id', ondelete='CASCADE', onupdate='CASCADE'), primary_key=True),
21
-        sa.Column('user_id', sa.Integer, sa.ForeignKey('users.user_id', ondelete='CASCADE', onupdate='CASCADE'), primary_key=True),
22
-        sa.Column('view_datetime', sa.DateTime, server_default=sa.func.now(), unique=False, nullable=False)
23
-    )
24
-
25
-
26
-def downgrade():
27
-    op.drop_table('revision_read_status')
28
-

+ 0 - 26
tracim/migration/versions/534c4594ed29_add_calendar_enabled_column_to_workspace.py View File

@@ -1,26 +0,0 @@
1
-"""Add calendar_enabled column to Workspace
2
-
3
-Revision ID: 534c4594ed29
4
-Revises: da12239d9da0
5
-Create Date: 2016-05-31 13:02:28.301984
6
-
7
-"""
8
-
9
-# revision identifiers, used by Alembic.
10
-revision = '534c4594ed29'
11
-down_revision = 'da12239d9da0'
12
-
13
-from alembic import op
14
-import sqlalchemy as sa
15
-
16
-
17
-def upgrade():
18
-    ### commands auto generated by Alembic - please adjust! ###
19
-    op.add_column('workspaces', sa.Column('calendar_enabled', sa.Boolean(), nullable=False, server_default='0'))
20
-    ### end Alembic commands ###
21
-
22
-
23
-def downgrade():
24
-    ### commands auto generated by Alembic - please adjust! ###
25
-    op.drop_column('workspaces', 'calendar_enabled')
26
-    ### end Alembic commands ###

+ 0 - 31
tracim/migration/versions/59fc98c3c965_delete_content_file_name_column.py View File

@@ -1,31 +0,0 @@
1
-"""delete content file name column
2
-
3
-Revision ID: 59fc98c3c965
4
-Revises: 15305f71bfda
5
-Create Date: 2016-11-25 14:55:22.176175
6
-
7
-"""
8
-
9
-# revision identifiers, used by Alembic.
10
-revision = '59fc98c3c965'
11
-down_revision = '15305f71bfda'
12
-
13
-from alembic import op
14
-import sqlalchemy as sa
15
-
16
-
17
-def upgrade():
18
-    op.drop_column('content_revisions', 'file_name')
19
-
20
-
21
-def downgrade():
22
-    op.add_column(
23
-        'content_revisions',
24
-        sa.Column(
25
-            'file_name',
26
-            sa.VARCHAR(length=255),
27
-            server_default=sa.text("''::character varying"),
28
-            autoincrement=False,
29
-            nullable=False
30
-        ),
31
-    )

+ 0 - 38
tracim/migration/versions/69fb10c3d6f0_files_on_disk.py View File

@@ -1,38 +0,0 @@
1
-"""files on disk.
2
-
3
-Revision ID: 69fb10c3d6f0
4
-Revises: c1cea4bbae16
5
-Create Date: 2017-06-07 17:25:47.306472
6
-
7
-"""
8
-
9
-from alembic import op
10
-from depot.fields.sqlalchemy import UploadedFileField
11
-import sqlalchemy as sa
12
-
13
-# revision identifiers, used by Alembic.
14
-revision = '69fb10c3d6f0'
15
-down_revision = 'c1cea4bbae16'
16
-
17
-
18
-# INFO - A.P - 2017-07-20 - alembic batch migrations
19
-# http://alembic.zzzcomputing.com/en/latest/batch.html
20
-# This migration uses alembic batch mode, a workaround allowing to enforce
21
-# ALTER statement with SQLite while maintaining the traditional behavior of
22
-# the commented lines on other RDBMS.
23
-
24
-
25
-def upgrade():
26
-    """Adds the depot file in revision."""
27
-    # op.add_column('content_revisions',
28
-    #               sa.Column('depot_file',
29
-    #                         UploadedFileField))
30
-    with op.batch_alter_table('content_revisions') as batch_op:
31
-        batch_op.add_column(sa.Column('depot_file', UploadedFileField))
32
-
33
-
34
-def downgrade():
35
-    """Drops the depot file in revision."""
36
-    # op.drop_column('content_revisions', 'depot_file')
37
-    with op.batch_alter_table('content_revisions') as batch_op:
38
-        batch_op.drop_column('depot_file')

+ 0 - 99
tracim/migration/versions/913efdf409e5_all_files_also_on_disk.py View File

@@ -1,99 +0,0 @@
1
-"""all files also on disk.
2
-
3
-Revision ID: 913efdf409e5
4
-Revises: 69fb10c3d6f0
5
-Create Date: 2017-07-12 15:44:20.568447
6
-
7
-"""
8
-
9
-import shutil
10
-
11
-from alembic import context
12
-from alembic import op
13
-from depot.fields.sqlalchemy import UploadedFileField
14
-from depot.fields.upload import UploadedFile
15
-from depot.io.utils import FileIntent
16
-from depot.manager import DepotManager
17
-import sqlalchemy as sa
18
-from sqlalchemy.sql.expression import func
19
-
20
-# revision identifiers, used by Alembic.
21
-revision = '913efdf409e5'
22
-down_revision = '69fb10c3d6f0'
23
-
24
-
25
-revision_helper = sa.Table(
26
-    'content_revisions',
27
-    sa.MetaData(),
28
-    sa.Column('revision_id', sa.Integer, primary_key=True),
29
-    sa.Column('label', sa.String(1024), nullable=False),
30
-    sa.Column('file_extension', sa.String(255), nullable=False),
31
-    sa.Column('file_mimetype', sa.String(255), nullable=False),
32
-    sa.Column('file_content', sa.LargeBinary),
33
-    sa.Column('depot_file', UploadedFileField, nullable=True),
34
-    sa.Column('type', sa.String(32), nullable=False),
35
-)
36
-
37
-
38
-def configure_depot():
39
-    """Configure Depot."""
40
-    depot_storage_name = context.config.get_main_option('depot_storage_name')
41
-    depot_storage_path = context.config.get_main_option('depot_storage_dir')
42
-    depot_storage_settings = {'depot.storage_path': depot_storage_path}
43
-    DepotManager.configure(
44
-        depot_storage_name,
45
-        depot_storage_settings,
46
-    )
47
-
48
-
49
-def delete_files_on_disk(connection: sa.engine.Connection):
50
-    """Deletes files from disk and their references in database."""
51
-    delete_query = revision_helper.update() \
52
-        .where(revision_helper.c.type == 'file') \
53
-        .where(revision_helper.c.depot_file.isnot(None)) \
54
-        .values(depot_file=None)
55
-    connection.execute(delete_query)
56
-    depot_storage_path = context.config.get_main_option('depot_storage_dir')
57
-    shutil.rmtree(depot_storage_path, ignore_errors=True)
58
-
59
-
60
-def upgrade():
61
-    """
62
-    Sets all depot files for file typed revisions.
63
-
64
-    Until now, files are both in database and, for the newly created
65
-    ones, on disk. In order to simplify the migration, this procedure
66
-    will:
67
-    - delete the few files on disk,
68
-    - create all files on disk from database.
69
-    """
70
-    # Creates files depot used in this migration
71
-    configure_depot()
72
-    connection = op.get_bind()
73
-    delete_files_on_disk(connection=connection)
74
-    select_query = revision_helper.select() \
75
-        .where(revision_helper.c.type == 'file') \
76
-        .where(revision_helper.c.depot_file.is_(None)) \
77
-        .where(func.length(revision_helper.c.file_content) > 0)
78
-    files = connection.execute(select_query).fetchall()
79
-    for file in files:
80
-        file_filename = '{0}{1}'.format(
81
-            file.label,
82
-            file.file_extension,
83
-        )
84
-        depot_file_intent = FileIntent(
85
-            file.file_content,
86
-            file_filename,
87
-            file.file_mimetype,
88
-        )
89
-        depot_file_field = UploadedFile(depot_file_intent, 'tracim')
90
-        update_query = revision_helper.update() \
91
-            .where(revision_helper.c.revision_id == file.revision_id) \
92
-            .values(depot_file=depot_file_field)
93
-        connection.execute(update_query)
94
-
95
-
96
-def downgrade():
97
-    """Resets depot file for file typed revisions."""
98
-    connection = op.get_bind()
99
-    delete_files_on_disk(connection=connection)

+ 0 - 28
tracim/migration/versions/b4b8d57b54e5_add_hash_column_for_digest_.py View File

@@ -1,28 +0,0 @@
1
-"""add hash column for digest authentication
2
-
3
-Revision ID: b4b8d57b54e5
4
-Revises: 534c4594ed29
5
-Create Date: 2016-08-11 10:27:28.951506
6
-
7
-"""
8
-
9
-# revision identifiers, used by Alembic.
10
-revision = 'b4b8d57b54e5'
11
-down_revision = 'bdb195ed95bb'
12
-
13
-from alembic import op
14
-from sqlalchemy import Column, Unicode, Boolean
15
-
16
-
17
-def upgrade():
18
-    op.add_column('users', Column('webdav_left_digest_response_hash', Unicode(128)))
19
-    op.add_column('content_revisions', Column('is_temporary', Boolean(), unique=False, nullable=True))
20
-    op.execute('''
21
-        UPDATE content_revisions
22
-        SET is_temporary = FALSE
23
-        ''')
24
-    op.alter_column('content_revisions', 'is_temporary', nullable=False)
25
-
26
-def downgrade():
27
-    op.drop_column('users', 'webdav_left_digest_response_hash')
28
-    op.drop_column('content_revisions', 'is_temporary')

+ 0 - 22
tracim/migration/versions/b73e57760b36_add_user_field_for_imported_profiles.py View File

@@ -1,22 +0,0 @@
1
-"""Add User field for imported profiles
2
-
3
-Revision ID: b73e57760b36
4
-Revises: 43a323cc661
5
-Create Date: 2016-02-09 11:00:22.694054
6
-
7
-"""
8
-
9
-# revision identifiers, used by Alembic.
10
-revision = 'b73e57760b36'
11
-down_revision = '43a323cc661'
12
-
13
-import sqlalchemy as sa
14
-from alembic import op
15
-
16
-
17
-def upgrade():
18
-    op.add_column('users', sa.Column('imported_from', sa.Unicode(length=32), nullable=True))
19
-
20
-
21
-def downgrade():
22
-    op.drop_column('users', 'imported_from')

+ 0 - 28
tracim/migration/versions/bdb195ed95bb_user_auth_token_columns.py View File

@@ -1,28 +0,0 @@
1
-"""User auth token columns
2
-
3
-Revision ID: bdb195ed95bb
4
-Revises: 534c4594ed29
5
-Create Date: 2016-07-28 15:38:18.889151
6
-
7
-"""
8
-
9
-# revision identifiers, used by Alembic.
10
-revision = 'bdb195ed95bb'
11
-down_revision = '534c4594ed29'
12
-
13
-from alembic import op
14
-import sqlalchemy as sa
15
-
16
-
17
-def upgrade():
18
-    ### commands auto generated by Alembic - please adjust! ###
19
-    op.add_column('users', sa.Column('auth_token', sa.Unicode(length=255), nullable=True))
20
-    op.add_column('users', sa.Column('auth_token_created', sa.DateTime(), nullable=True))
21
-    ### end Alembic commands ###
22
-
23
-
24
-def downgrade():
25
-    ### commands auto generated by Alembic - please adjust! ###
26
-    op.drop_column('users', 'auth_token_created')
27
-    op.drop_column('users', 'auth_token')
28
-    ### end Alembic commands ###

+ 0 - 78
tracim/migration/versions/c1cea4bbae16_file_extentions_value_for_pages_and_.py View File

@@ -1,78 +0,0 @@
1
-"""file_extentions value for Pages and Threads
2
-
3
-Revision ID: c1cea4bbae16
4
-Revises: 59fc98c3c965
5
-Create Date: 2016-11-30 10:41:51.893531
6
-
7
-"""
8
-
9
-# revision identifiers, used by Alembic.
10
-
11
-revision = 'c1cea4bbae16'
12
-down_revision = '59fc98c3c965'
13
-
14
-from alembic import op
15
-import sqlalchemy as sa
16
-
17
-content_revision_helper = sa.Table(
18
-    'content_revisions',
19
-    sa.MetaData(),
20
-    sa.Column('revision_id', sa.Integer, primary_key=True),
21
-    sa.Column('content_id', sa.ForeignKey(u'content.id'), nullable=False),
22
-    sa.Column('owner_id', sa.ForeignKey(u'users.user_id'), index=True),
23
-    sa.Column('label', sa.String(1024), nullable=False),
24
-    sa.Column('description', sa.Text, nullable=False),
25
-    sa.Column('file_extension', sa.String(255), nullable=False),
26
-    sa.Column('file_mimetype', sa.String(255), nullable=False),
27
-    sa.Column('file_content', sa.LargeBinary),
28
-    sa.Column('properties', sa.Text, nullable=False),
29
-    sa.Column('type', sa.String(32), nullable=False),
30
-    sa.Column('status', sa.String(32), nullable=False),
31
-    sa.Column('created', sa.DateTime, nullable=False),
32
-    sa.Column('updated', sa.DateTime, nullable=False),
33
-    sa.Column('is_deleted', sa.Boolean, nullable=False),
34
-    sa.Column('is_archived', sa.Boolean, nullable=False),
35
-    sa.Column('is_temporary', sa.Boolean, nullable=False),
36
-    sa.Column('revision_type', sa.String(32), nullable=False),
37
-    sa.Column('workspace_id', sa.ForeignKey(u'workspaces.workspace_id')),
38
-    sa.Column('parent_id', sa.ForeignKey(u'content.id'), index=True),
39
-)
40
-
41
-
42
-def upgrade():
43
-    connection = op.get_bind()
44
-
45
-    for content_revision in connection.execute(
46
-            content_revision_helper.select()
47
-    ):
48
-        if content_revision.type in ('page', 'thread'):
49
-            # Update record
50
-            connection.execute(
51
-                content_revision_helper.update()
52
-                    .where(
53
-                        content_revision_helper.c.revision_id ==
54
-                        content_revision.revision_id
55
-                    ).values(
56
-                        file_extension='.html',
57
-                    )
58
-                )
59
-
60
-
61
-def downgrade():
62
-    connection = op.get_bind()
63
-
64
-    for content_revision in connection.execute(
65
-            content_revision_helper.select()
66
-    ):
67
-        # On work with FILE
68
-        if content_revision.type in ('page', 'thread'):
69
-            # Update record
70
-            connection.execute(
71
-                content_revision_helper.update()
72
-                    .where(
73
-                        content_revision_helper.c.revision_id ==
74
-                        content_revision.revision_id
75
-                    ).values(
76
-                        file_extension='',
77
-                    )
78
-                )

+ 0 - 187
tracim/migration/versions/da12239d9da0_delete_content_view.py View File

@@ -1,187 +0,0 @@
1
-"""delete_content_view
2
-
3
-Revision ID: da12239d9da0
4
-Revises: b73e57760b36
5
-Create Date: 2016-03-04 15:59:05.828757
6
-
7
-"""
8
-
9
-# revision identifiers, used by Alembic.
10
-revision = 'da12239d9da0'
11
-down_revision = 'b73e57760b36'
12
-
13
-import sqlalchemy as sa
14
-from alembic import op
15
-from sqlalchemy.dialects import postgresql
16
-
17
-
18
-def set_field_where_null(field_name, value="''"):
19
-    op.execute("UPDATE content_revisions SET %s = %s WHERE %s IS NULL" % (field_name, value, field_name))
20
-
21
-
22
-def set_field_to_null_where_empty_string(field_name):
23
-    op.execute("UPDATE content_revisions SET %s = NULL WHERE %s = ''" % (field_name, field_name))
24
-
25
-fields_names_to_empty_string = ('file_mimetype', 'file_name', 'label', 'properties',
26
-                                'revision_type', 'status', 'description', 'label')
27
-
28
-
29
-def upgrade():
30
-    ### commands auto generated by Alembic - please adjust! ###
31
-
32
-    # Drop triggers
33
-    op.execute("DROP TRIGGER trg__contents__on_insert__set_created ON content_revisions")
34
-    op.execute("DROP TRIGGER trg__contents__on_update__set_updated ON content_revisions")
35
-    op.execute("DROP TRIGGER trg__contents__on_update On contents")
36
-    op.execute("DROP TRIGGER trg__workspaces__on_insert__set_created ON workspaces")
37
-    op.execute("DROP TRIGGER trg__workspaces__on_update__set_updated ON workspaces")
38
-    op.execute("DROP VIEW contents")
39
-
40
-    # Set empty string on future non null fields
41
-    for field_name in fields_names_to_empty_string:
42
-        set_field_where_null(field_name)
43
-
44
-    op.create_table('content',
45
-                    sa.Column('id', sa.Integer(), nullable=False),
46
-                    sa.PrimaryKeyConstraint('id', name=op.f('pk__content'))
47
-                    )
48
-
49
-    # Create contents and reinit auto increment
50
-    op.execute("INSERT INTO content (id) SELECT DISTINCT(content_id) FROM content_revisions;")
51
-    op.execute("select setval('content_id_seq', (select max(id)+1 from content), false)")
52
-
53
-    op.alter_column('content_revisions', 'created',
54
-                    existing_type=postgresql.TIMESTAMP(),
55
-                    nullable=False,
56
-                    server_default=sa.func.now())
57
-    op.alter_column('content_revisions', 'file_mimetype',
58
-                    existing_type=sa.VARCHAR(length=255),
59
-                    nullable=False,
60
-                    server_default='')
61
-    op.alter_column('content_revisions', 'file_name',
62
-                    existing_type=sa.VARCHAR(length=255),
63
-                    nullable=False,
64
-                    server_default='')
65
-    op.alter_column('content_revisions', 'label',
66
-                    existing_type=sa.VARCHAR(length=1024),
67
-                    nullable=False,
68
-                    server_default='')
69
-    op.alter_column('content_revisions', 'properties',
70
-                    existing_type=sa.TEXT(),
71
-                    nullable=False,
72
-                    server_default='')
73
-    op.alter_column('content_revisions', 'revision_type',
74
-                    existing_type=sa.VARCHAR(length=32),
75
-                    nullable=False,
76
-                    server_default='')
77
-    op.alter_column('content_revisions', 'status',
78
-                    existing_type=sa.VARCHAR(length=32),
79
-                    nullable=False,
80
-                    existing_server_default=sa.text("'new'::character varying"),
81
-                    server_default='')
82
-    op.alter_column('content_revisions', 'updated',
83
-                    existing_type=postgresql.TIMESTAMP(),
84
-                    nullable=False,
85
-                    server_default=sa.func.now())
86
-    op.create_foreign_key(op.f('fk__content_revisions__content_id__content'), 'content_revisions', 'content',
87
-                          ['content_id'], ['id'])
88
-    op.create_foreign_key(op.f('fk__content_revisions__workspace_id__workspaces'), 'content_revisions', 'workspaces',
89
-                          ['workspace_id'], ['workspace_id'])
90
-    op.create_foreign_key(op.f('fk__content_revisions__parent_id__content'), 'content_revisions', 'content',
91
-                          ['parent_id'], ['id'])
92
-    op.alter_column('user_workspace', 'role',
93
-                    existing_type=sa.INTEGER(),
94
-                    nullable=False)
95
-    op.drop_constraint('fk__user_workspace__user_id', 'user_workspace', type_='foreignkey')
96
-    op.drop_constraint('fk__user_workspace__workspace_id', 'user_workspace', type_='foreignkey')
97
-    op.create_foreign_key(op.f('fk__user_workspace__user_id__users'), 'user_workspace', 'users', ['user_id'],
98
-                          ['user_id'])
99
-    op.create_foreign_key(op.f('fk__user_workspace__workspace_id__workspaces'), 'user_workspace', 'workspaces',
100
-                          ['workspace_id'], ['workspace_id'])
101
-    op.alter_column('workspaces', 'created',
102
-                    existing_type=postgresql.TIMESTAMP(),
103
-                    nullable=False,
104
-                    server_default=sa.func.now())
105
-    op.alter_column('workspaces', 'description',
106
-                    existing_type=sa.TEXT(),
107
-                    nullable=False,
108
-                    server_default='')
109
-    op.alter_column('workspaces', 'label',
110
-                    existing_type=sa.VARCHAR(length=1024),
111
-                    nullable=False,
112
-                    server_default='')
113
-    op.alter_column('workspaces', 'updated',
114
-                    existing_type=postgresql.TIMESTAMP(),
115
-                    nullable=False,
116
-                    server_default=sa.func.now())
117
-    ### end Alembic commands ###
118
-
119
-
120
-def downgrade():
121
-    ### commands auto generated by Alembic - please adjust! ###
122
-    op.alter_column('workspaces', 'updated',
123
-                    existing_type=postgresql.TIMESTAMP(),
124
-                    nullable=True)
125
-    op.alter_column('workspaces', 'label',
126
-                    existing_type=sa.VARCHAR(length=1024),
127
-                    nullable=True)
128
-    op.alter_column('workspaces', 'description',
129
-                    existing_type=sa.TEXT(),
130
-                    nullable=True)
131
-    op.alter_column('workspaces', 'created',
132
-                    existing_type=postgresql.TIMESTAMP(),
133
-                    nullable=True)
134
-    op.drop_constraint(op.f('fk__user_workspace__workspace_id__workspaces'), 'user_workspace', type_='foreignkey')
135
-    op.drop_constraint(op.f('fk__user_workspace__user_id__users'), 'user_workspace', type_='foreignkey')
136
-    op.create_foreign_key('fk__user_workspace__workspace_id', 'user_workspace', 'workspaces', ['workspace_id'],
137
-                          ['workspace_id'], onupdate='CASCADE', ondelete='CASCADE')
138
-    op.create_foreign_key('fk__user_workspace__user_id', 'user_workspace', 'users', ['user_id'], ['user_id'],
139
-                          onupdate='CASCADE', ondelete='CASCADE')
140
-    op.alter_column('user_workspace', 'role',
141
-                    existing_type=sa.INTEGER(),
142
-                    nullable=True)
143
-    op.drop_constraint(op.f('fk__content_revisions__parent_id__content'), 'content_revisions', type_='foreignkey')
144
-    op.drop_constraint(op.f('fk__content_revisions__workspace_id__workspaces'), 'content_revisions', type_='foreignkey')
145
-    op.drop_constraint(op.f('fk__content_revisions__content_id__content'), 'content_revisions', type_='foreignkey')
146
-    op.alter_column('content_revisions', 'updated',
147
-                    existing_type=postgresql.TIMESTAMP(),
148
-                    nullable=True)
149
-    op.alter_column('content_revisions', 'status',
150
-                    existing_type=sa.VARCHAR(length=32),
151
-                    nullable=True,
152
-                    existing_server_default=sa.text("'new'::character varying"))
153
-    op.alter_column('content_revisions', 'revision_type',
154
-                    existing_type=sa.VARCHAR(length=32),
155
-                    nullable=True)
156
-    op.alter_column('content_revisions', 'properties',
157
-                    existing_type=sa.TEXT(),
158
-                    nullable=True)
159
-    op.alter_column('content_revisions', 'label',
160
-                    existing_type=sa.VARCHAR(length=1024),
161
-                    nullable=True)
162
-    op.alter_column('content_revisions', 'file_name',
163
-                    existing_type=sa.VARCHAR(length=255),
164
-                    nullable=True)
165
-    op.alter_column('content_revisions', 'file_mimetype',
166
-                    existing_type=sa.VARCHAR(length=255),
167
-                    nullable=True)
168
-    op.alter_column('content_revisions', 'created',
169
-                    existing_type=postgresql.TIMESTAMP(),
170
-                    nullable=True)
171
-    op.drop_table('content')
172
-
173
-    for field_name in fields_names_to_empty_string:
174
-        set_field_to_null_where_empty_string(field_name)
175
-
176
-    op.execute("""
177
-CREATE VIEW contents AS
178
-    SELECT DISTINCT ON (content_revisions.content_id) content_revisions.content_id, content_revisions.parent_id, content_revisions.type, content_revisions.created, content_revisions.updated, content_revisions.label, content_revisions.description, content_revisions.status, content_revisions.file_name, content_revisions.file_content, content_revisions.file_mimetype, content_revisions.owner_id, content_revisions.workspace_id, content_revisions.is_deleted, content_revisions.is_archived, content_revisions.properties, content_revisions.revision_type FROM content_revisions ORDER BY content_revisions.content_id, content_revisions.updated DESC, content_revisions.created DESC;
179
-
180
-
181
-CREATE TRIGGER trg__contents__on_insert__set_created BEFORE INSERT ON content_revisions FOR EACH ROW EXECUTE PROCEDURE set_created();
182
-CREATE TRIGGER trg__contents__on_update__set_updated BEFORE UPDATE ON content_revisions FOR EACH ROW EXECUTE PROCEDURE set_updated();
183
-CREATE TRIGGER trg__contents__on_update INSTEAD OF UPDATE ON contents FOR EACH ROW EXECUTE PROCEDURE update_node();
184
-CREATE TRIGGER trg__workspaces__on_insert__set_created BEFORE INSERT ON workspaces FOR EACH ROW EXECUTE PROCEDURE set_created();
185
-CREATE TRIGGER trg__workspaces__on_update__set_updated BEFORE UPDATE ON workspaces FOR EACH ROW EXECUTE PROCEDURE set_updated();
186
-""")
187
-    ### end Alembic commands ###

+ 0 - 33
tracim/migration/versions/e31ddc009b37_add_content_file_extension_column.py View File

@@ -1,33 +0,0 @@
1
-"""add_content_file_extension_column
2
-
3
-Revision ID: e31ddc009b37
4
-Revises: 2cd20ff3d23a
5
-Create Date: 2016-11-25 10:43:23.700867
6
-
7
-"""
8
-
9
-# revision identifiers, used by Alembic.
10
-revision = 'e31ddc009b37'
11
-down_revision = '2cd20ff3d23a'
12
-
13
-from alembic import op
14
-import sqlalchemy as sa
15
-
16
-
17
-def upgrade():
18
-    op.add_column(
19
-        'content_revisions',
20
-        sa.Column(
21
-            'file_extension',
22
-            sa.Unicode(length=255),
23
-            server_default='',
24
-            nullable=False,
25
-        )
26
-    )
27
-
28
-
29
-def downgrade():
30
-    op.drop_column(
31
-        'content_revisions',
32
-        'file_extension',
33
-    )

+ 0 - 66
tracim/migration/versions/f3852e1349c4_all_files_only_on_disk.py View File

@@ -1,66 +0,0 @@
1
-"""all files only on disk.
2
-
3
-Revision ID: f3852e1349c4
4
-Revises: 913efdf409e5
5
-Create Date: 2017-07-24 17:15:54.278141
6
-
7
-"""
8
-
9
-from alembic import context
10
-from alembic import op
11
-
12
-from depot.fields.sqlalchemy import UploadedFileField
13
-from depot.manager import DepotManager
14
-
15
-import sqlalchemy as sa
16
-
17
-# revision identifiers, used by Alembic.
18
-revision = 'f3852e1349c4'
19
-down_revision = '913efdf409e5'
20
-
21
-
22
-def configure_depot():
23
-    """Configure Depot."""
24
-    depot_storage_name = context.config.get_main_option('depot_storage_name')
25
-    depot_storage_path = context.config.get_main_option('depot_storage_dir')
26
-    depot_storage_settings = {'depot.storage_path': depot_storage_path}
27
-    DepotManager.configure(
28
-        depot_storage_name,
29
-        depot_storage_settings,
30
-    )
31
-
32
-
33
-revision_helper = sa.Table(
34
-    'content_revisions',
35
-    sa.MetaData(),
36
-    sa.Column('revision_id', sa.Integer, primary_key=True),
37
-    sa.Column('file_content', sa.LargeBinary),
38
-    sa.Column('depot_file', UploadedFileField, nullable=True),
39
-    sa.Column('type', sa.String(32), nullable=False),
40
-)
41
-
42
-
43
-def upgrade():
44
-    """Drop the file content from revision."""
45
-    with op.batch_alter_table('content_revisions') as batch_op:
46
-        batch_op.drop_column('file_content')
47
-
48
-
49
-def downgrade():
50
-    """Add the file content in revision."""
51
-    with op.batch_alter_table('content_revisions') as batch_op:
52
-        batch_op.add_column(sa.Column('file_content', sa.LargeBinary))
53
-
54
-    configure_depot()
55
-    depot = DepotManager.get()
56
-    connection = op.get_bind()
57
-    select_query = revision_helper.select() \
58
-        .where(revision_helper.c.type == 'file') \
59
-        .where(revision_helper.c.depot_file.isnot(None))
60
-    files = connection.execute(select_query).fetchall()
61
-    for file in files:
62
-        depot_file_content = depot.get(file.depot_file).read()
63
-        update_query = revision_helper.update() \
64
-            .where(revision_helper.c.revision_id == file.revision_id) \
65
-            .values(file_content=depot_file_content)
66
-        connection.execute(update_query)