~facundo/filesync-server/trunk

« back to all changes in this revision

Viewing changes to src/backends/db/schemas/fsync_shard/patch_6.py

  • Committer: Facundo Batista
  • Date: 2015-08-05 13:10:02 UTC
  • Revision ID: facundo@taniquetil.com.ar-20150805131002-he7b7k704d8o7js6
First released version.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# Copyright 2008-2015 Canonical
 
2
#
 
3
# This program is free software: you can redistribute it and/or modify
 
4
# it under the terms of the GNU Affero General Public License as
 
5
# published by the Free Software Foundation, either version 3 of the
 
6
# License, or (at your option) any later version.
 
7
#
 
8
# This program is distributed in the hope that it will be useful,
 
9
# but WITHOUT ANY WARRANTY; without even the implied warranty of
 
10
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
11
# GNU Affero General Public License for more details.
 
12
#
 
13
# You should have received a copy of the GNU Affero General Public License
 
14
# along with this program. If not, see <http://www.gnu.org/licenses/>.
 
15
#
 
16
# For further info, check  http://launchpad.net/filesync-server
 
17
 
 
18
"""Support for REST Resumable Uploads."""
 
19
 
 
20
SQL = [
 
21
    """
 
22
    CREATE TABLE resumable_upload (
 
23
        upload_id uuid PRIMARY KEY NOT NULL,
 
24
        owner_id integer NOT NULL REFERENCES StorageUserInfo ON DELETE CASCADE,
 
25
        volume_path text NOT NULL,
 
26
        size bigint NOT NULL,
 
27
        mimetype text,
 
28
        when_started timestamp without time zone
 
29
            default timezone('UTC'::text, now()) not null,
 
30
        when_last_active timestamp without time zone
 
31
            default timezone('UTC'::text, now()) not null,
 
32
        status lifecycle_status default 'Live'::lifecycle_status not null,
 
33
        multipart_id bytea NOT NULL,
 
34
        storage_key uuid NOT NULL,
 
35
        part_count bigint NOT NULL,
 
36
        uploaded_bytes bigint NOT NULL,
 
37
        hash_context bytea,
 
38
        magic_hash_context bytea,
 
39
        crc_context int
 
40
    );
 
41
    """,
 
42
    """
 
43
    COMMENT ON TABLE resumable_upload IS
 
44
        'Tracks resumable upload that will result in a \
 
45
         ContentBlob being created'
 
46
    """,
 
47
    """
 
48
    COMMENT ON COLUMN resumable_upload.upload_id IS
 
49
        'Unique identifier for the upload attempt';
 
50
    """,
 
51
    """
 
52
    COMMENT ON COLUMN resumable_upload.owner_id IS
 
53
        'The id of the owner of the file';
 
54
    """,
 
55
    """
 
56
    COMMENT ON COLUMN resumable_upload.volume_path IS
 
57
        'The volume path for the file which will be created';
 
58
    """,
 
59
    """
 
60
    COMMENT ON COLUMN resumable_upload.size IS
 
61
        'The size in bytes of the file being uploaded';
 
62
    """,
 
63
    """
 
64
    COMMENT ON COLUMN resumable_upload.when_started IS
 
65
        'Timestamp when this upload started';
 
66
    """,
 
67
    """
 
68
    COMMENT ON COLUMN resumable_upload.when_last_active IS
 
69
        'Timestamp for when the last chunk was created for this upload action';
 
70
    """,
 
71
    """
 
72
    COMMENT ON COLUMN resumable_upload.multipart_id IS
 
73
        'The upload_id returned by S3';
 
74
    """,
 
75
    """
 
76
    COMMENT ON COLUMN resumable_upload.storage_key IS
 
77
        'The S3 objectName which will be created by this upload';
 
78
    """,
 
79
    """
 
80
    COMMENT ON COLUMN resumable_upload.part_count IS
 
81
        'The number of parts uploaded so far';
 
82
    """,
 
83
    """
 
84
    COMMENT ON COLUMN resumable_upload.uploaded_bytes IS
 
85
        'The number of bytes uploaded so far';
 
86
    """,
 
87
    """
 
88
    COMMENT ON COLUMN resumable_upload.hash_context IS
 
89
        'The state of the resumable hasher';
 
90
    """,
 
91
    """
 
92
    COMMENT ON COLUMN resumable_upload.magic_hash_context IS
 
93
        'The state of the resumable magic hasher';
 
94
    """,
 
95
    """
 
96
    COMMENT ON COLUMN resumable_upload.crc_context IS
 
97
        'The state of the resumable compressor';
 
98
    """,
 
99
    """
 
100
    GRANT SELECT,INSERT,DELETE,UPDATE
 
101
        ON TABLE resumable_upload TO storage, webapp;
 
102
    """,
 
103
    """
 
104
    CREATE INDEX resumable_upload_owner_idx ON resumable_upload(owner_id);
 
105
    """,
 
106
]
 
107
 
 
108
 
 
109
def apply(store):
 
110
    """Apply the patch."""
 
111
    for sql in SQL:
 
112
        store.execute(sql)