ceph / chacra

A binary/file REST API to aid in multi-distro|arch|release management
9 stars 18 forks source link

create a `BigInteger` migration #262

Closed alfredodeza closed 5 years ago

alfredodeza commented 5 years ago

This is needed because the size type was int and it maxed out at 2**31 which is roughly a bit over 2GBs in bytes. Created the migration manually because alembic doesn't support updating types automatically.

existing database:

$ psql postgres -U alfredo -d chacra
psql: warning: extra command-line argument "postgres" ignored
psql (11.1, server 9.4.4)
Type "help" for help.

chacra=# \d+ binaries
                                                              Table "public.binaries"
     Column     |            Type             | Collation | Nullable |               Default                | Storage  | Stats target | Description
----------------+-----------------------------+-----------+----------+--------------------------------------+----------+--------------+-------------
 id             | integer                     |           | not null | nextval('binaries_id_seq'::regclass) | plain    |              |
 name           | character varying(256)      |           | not null |                                      | extended |              |
 path           | character varying(256)      |           |          |                                      | extended |              |
 ref            | character varying(256)      |           |          |                                      | extended |              |
 sha1           | character varying(256)      |           |          |                                      | extended |              |
 distro         | character varying(256)      |           | not null |                                      | extended |              |
 distro_version | character varying(256)      |           | not null |                                      | extended |              |
 arch           | character varying(256)      |           | not null |                                      | extended |              |
 flavor         | character varying(256)      |           | not null |                                      | extended |              |
 built_by       | character varying(256)      |           |          |                                      | extended |              |
 created        | timestamp without time zone |           |          |                                      | plain    |              |
 modified       | timestamp without time zone |           |          |                                      | plain    |              |
 signed         | boolean                     |           |          |                                      | plain    |              |
 size           | integer                     |           |          |                                      | plain    |              |
 checksum       | character varying(256)      |           |          |                                      | extended |              |
 project_id     | integer                     |           |          |                                      | plain    |              |
 repo_id        | integer                     |           |          |                                      | plain    |              |
Indexes:
    "binaries_pkey" PRIMARY KEY, btree (id)
    "ix_binaries_arch" btree (arch)
    "ix_binaries_created" btree (created)
    "ix_binaries_distro" btree (distro)
    "ix_binaries_distro_version" btree (distro_version)
    "ix_binaries_flavor" btree (flavor)
    "ix_binaries_modified" btree (modified)
    "ix_binaries_name" btree (name)
    "ix_binaries_ref" btree (ref)
    "ix_binaries_sha1" btree (sha1)
Foreign-key constraints:
    "binaries_project_id_fkey" FOREIGN KEY (project_id) REFERENCES projects(id)
    "binaries_repo_id_fkey" FOREIGN KEY (repo_id) REFERENCES repos(id)

Update with the migration:

(chacra) papaya-2[bigint-migration*] ~/python/chacra ᓆ alembic -c alembic.ini stamp 4021ff3a9dc5
INFO  [alembic.runtime.migration] Context impl PostgresqlImpl.
INFO  [alembic.runtime.migration] Will assume transactional DDL.
INFO  [alembic.runtime.migration] Running stamp_revision 52d176771ae6 -> 4021ff3a9dc5
(chacra) papaya-2[bigint-migration*] ~/python/chacra ᓆ alembic -c alembic.ini upgrade head
INFO  [alembic.runtime.migration] Context impl PostgresqlImpl.
INFO  [alembic.runtime.migration] Will assume transactional DDL.
INFO  [alembic.runtime.migration] Running upgrade 4021ff3a9dc5 -> 52d176771ae6, BigInteger size
(chacra) papaya-2[bigint-migration*] ~/python/chacra ᓆ psql postgres -U alfredo -d chacra
psql: warning: extra command-line argument "postgres" ignored
psql (11.1, server 9.4.4)
Type "help" for help.

chacra=# \d+ binaries
                                                              Table "public.binaries"
     Column     |            Type             | Collation | Nullable |               Default                | Storage  | Stats target | Description
----------------+-----------------------------+-----------+----------+--------------------------------------+----------+--------------+-------------
 id             | integer                     |           | not null | nextval('binaries_id_seq'::regclass) | plain    |              |
 name           | character varying(256)      |           | not null |                                      | extended |              |
 path           | character varying(256)      |           |          |                                      | extended |              |
 ref            | character varying(256)      |           |          |                                      | extended |              |
 sha1           | character varying(256)      |           |          |                                      | extended |              |
 distro         | character varying(256)      |           | not null |                                      | extended |              |
 distro_version | character varying(256)      |           | not null |                                      | extended |              |
 arch           | character varying(256)      |           | not null |                                      | extended |              |
 flavor         | character varying(256)      |           | not null |                                      | extended |              |
 built_by       | character varying(256)      |           |          |                                      | extended |              |
 created        | timestamp without time zone |           |          |                                      | plain    |              |
 modified       | timestamp without time zone |           |          |                                      | plain    |              |
 signed         | boolean                     |           |          |                                      | plain    |              |
 size           | bigint                      |           |          |                                      | plain    |              |
 checksum       | character varying(256)      |           |          |                                      | extended |              |
 project_id     | integer                     |           |          |                                      | plain    |              |
 repo_id        | integer                     |           |          |                                      | plain    |              |
Indexes:
    "binaries_pkey" PRIMARY KEY, btree (id)
    "ix_binaries_arch" btree (arch)
    "ix_binaries_created" btree (created)
    "ix_binaries_distro" btree (distro)
    "ix_binaries_distro_version" btree (distro_version)
    "ix_binaries_flavor" btree (flavor)
    "ix_binaries_modified" btree (modified)
    "ix_binaries_name" btree (name)
    "ix_binaries_ref" btree (ref)
    "ix_binaries_sha1" btree (sha1)
Foreign-key constraints:
    "binaries_project_id_fkey" FOREIGN KEY (project_id) REFERENCES projects(id)
    "binaries_repo_id_fkey" FOREIGN KEY (repo_id) REFERENCES repos(id)
alfredodeza commented 5 years ago

@djgalloway we will need to run migrations once this gets in