Skip to content
Snippets Groups Projects

Draft: Migrate the database to schema v2

Open Auri requested to merge feat/v2-prep into master
2 unresolved threads

This is a partial rewrite of the database schema and the supporting application code. The goal is to prepare for larger future changes.

User impact

The only user-facing change of this patch is a fix for files created between the 23rd of February, 2019 (when the new API was deployed) and the 20th of April, 2019 (when a08978a9 was deployed). The migration script ensures that every key (now path) in the objects table (now object) has a leading slash. While this is technically a breaking change, I do not have a reason to believe any existing client would be affected.

Edited by Auri

Merge request reports

Ready to merge by members who can write to the target branch.
Loading

Activity

Filter activity
  • Approvals
  • Assignees & reviewers
  • Comments (from bots)
  • Comments (from users)
  • Commits & branches
  • Edits
  • Labels
  • Lock status
  • Mentions
  • Merge request status
  • Tracking
sql/v1tov2.sql 0 → 100644
34 -- reasonable use case.
35 CREATE DOMAIN url AS character varying(4096);
36
37 CREATE DOMAIN bucket_name AS character varying(32);
38
39 CREATE DOMAIN object_path AS character varying(4096);
40
41 -- Given '//foo/bar//baz', return '/foo/bar/baz'.
42 CREATE FUNCTION path_normalize(object_path) RETURNS object_path
43 IMMUTABLE STRICT
44 LANGUAGE SQL
45 AS $$SELECT regexp_replace($1, '/+', '/', 'g');$$;
46
47 -- Given '/foo/bar.baz.qux', return '/foo/bar'.
48 -- See bucket.enforce_unique_names and object.enforce_unique_name.
49 CREATE FUNCTION path_full_stem(object_path) RETURNS object_path
  • sql/v1tov2.sql 0 → 100644
    206 -- should afford us about 9EB :)
    207 ALTER COLUMN content_length SET DATA TYPE bigint,
    208 ALTER COLUMN sha256_digest SET DATA TYPE sha256,
    209 ALTER COLUMN md5_digest SET DATA TYPE md5,
    210 ALTER COLUMN location DROP DEFAULT,
    211 ALTER COLUMN location SET DATA TYPE url,
    212 ALTER COLUMN owned_by DROP DEFAULT,
    213 ALTER COLUMN owned_by SET DATA TYPE uuid USING owned_by::uuid,
    214 -- Casting timestamp to timestamp with time zone is equivalent to:
    215 -- USING (created_at as time zone current_setting('timezone'))
    216 ALTER COLUMN created_at SET DATA TYPE timestamp with time zone,
    217 ALTER COLUMN tombstoned_at SET DATA TYPE timestamp with time zone,
    218 -- DEFAULT NULL is implied on nullable columns.
    219 ALTER COLUMN tombstone_description DROP DEFAULT,
    220 ADD FOREIGN KEY (owned_by) REFERENCES user_ (id),
    221 ADD CHECK (content_length >= -1),
  • Auri added 3 commits

    added 3 commits

    • e15228a5 - sql/v1tov2: properly handle directories in path_full_stem
    • a01186b3 - sql/v1tov2: properly CHECK content_length
    • bfafe94e - sql/v1tov2: path_full_stem(path) is unique per-bucket

    Compare with previous version

  • Please register or sign in to reply
    Loading