Repository navigation
Migrate all IDs to bigint - #67
Merged
Merged
Conversation
sjha4
force-pushed
the
bigint
branch
15 times, most recently
from
September 3, 2026 17:49
f107f56 to
3412441
Compare
ianballou
reviewed
Sep 3, 2026
| up do | ||
| # SQLite's INTEGER type already supports 64-bit integers, skip for SQLite | ||
| # Check database adapter from environment variable set by Database class | ||
| db_adapter = ENV['CONTAINER_GATEWAY_DB_ADAPTER'] || '' |
Member
There was a problem hiding this comment.
It looks like we get database_type for free:
Suggested change
| db_adapter = ENV['CONTAINER_GATEWAY_DB_ADAPTER'] || '' | |
| db_adapter = database_type || '' |
2: require 'pry'
3: Sequel.migration do
4: up do
5: # SQLite's INTEGER type already supports 64-bit integers, skip for SQLite
6: # Check database adapter from environment variable set by Database class
=> 7: binding.pry
8: db_adapter = database_type || ''
9:
10: # Skip for SQLite (adapter will be 'sqlite', 'jdbc:sqlite', etc.)
11: unless db_adapter.to_s.downcase.include?('sqlite')
12: alter_table(:repositories) do
[1] pry(#<Sequel::SQLite::Database>)> database_type
=> :sqlite
Member
Author
There was a problem hiding this comment.
I remember rejecting this edit on claude 🙈 ..Will update..
ianballou
reviewed
Sep 3, 2026
ianballou
left a comment
Member
There was a problem hiding this comment.
The migration is working well on a live smart proxy with postgres:
container_gateway=# SELECT
child_ns.nspname AS fk_schema,
child_tbl.relname AS fk_table,
child_attr.attname AS fk_column,
format_type(child_attr.atttypid, NULL) AS fk_type,
parent_ns.nspname AS pk_schema,
parent_tbl.relname AS pk_table,
parent_attr.attname AS pk_column,
format_type(parent_attr.atttypid, NULL) AS pk_type,
CASE
WHEN format_type(child_attr.atttypid, NULL) = 'bigint'
AND format_type(parent_attr.atttypid, NULL) = 'bigint'
THEN 'PASS'
ELSE 'FAIL'
END AS status
FROM pg_constraint c
JOIN pg_class child_tbl ON c.conrelid = child_tbl.oid
JOIN pg_namespace child_ns ON child_tbl.relnamespace = child_ns.oid
JOIN pg_class parent_tbl ON c.confrelid = parent_tbl.oid
JOIN pg_namespace parent_ns ON parent_tbl.relnamespace = parent_ns.oid
CROSS JOIN LATERAL unnest(c.conkey, c.confkey) AS k(child_attnum, parent_attnum)
JOIN pg_attribute child_attr ON child_attr.attrelid = child_tbl.oid AND child_attr.attnum = k.child_attnum
JOIN pg_attribute parent_attr ON parent_attr.attrelid = parent_tbl.oid AND parent_attr.attnum = k.parent_attnum
WHERE c.contype = 'f'
AND child_ns.nspname NOT IN ('pg_catalog', 'information_schema')
ORDER BY status ASC, fk_schema, fk_table;
fk_schema | fk_table | fk_column | fk_type | pk_schema | pk_table | pk_column | pk_type | status
-----------+-----------------------+---------------+---------+-----------+--------------+-----------+---------+--------
public | authentication_tokens | user_id | bigint | public | users | id | bigint | PASS
public | hosts_repositories | repository_id | bigint | public | repositories | id | bigint | PASS
public | hosts_repositories | host_id | bigint | public | hosts | id | bigint | PASS
public | repositories_users | user_id | bigint | public | users | id | bigint | PASS
public | repositories_users | repository_id | bigint | public | repositories | id | bigint | PASS
(5 rows)
container_gateway=# SELECT
n.nspname AS schema_name,
t.relname AS table_name,
a.attname AS pk_column,
format_type(a.atttypid, NULL) AS data_type,
CASE
WHEN format_type(a.atttypid, NULL) = 'bigint' THEN 'PASS'
ELSE 'FAIL'
END AS status
FROM pg_constraint c
JOIN pg_class t ON c.conrelid = t.oid
JOIN pg_namespace n ON t.relnamespace = n.oid
JOIN pg_attribute a ON a.attrelid = t.oid AND a.attnum = ANY(c.conkey)
WHERE c.contype = 'p'
AND n.nspname NOT IN ('pg_catalog', 'information_schema')
ORDER BY status ASC, schema_name, table_name;
schema_name | table_name | pk_column | data_type | status
-------------+-----------------------+---------------+-----------+--------
public | authentication_tokens | id | bigint | PASS
public | hosts | id | bigint | PASS
public | hosts_repositories | host_id | bigint | PASS
public | hosts_repositories | repository_id | bigint | PASS
public | repositories | id | bigint | PASS
public | repositories_users | user_id | bigint | PASS
public | repositories_users | repository_id | bigint | PASS
public | users | id | bigint | PASS
(8 rows)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Migrate all ID fields in DB to bigint.
To test:
Check out branch
Set up a conf to mount repo's lib/ to installed gem's lib/ inside container using https://gist.github.com/sjha4/4b539989d89640109d562e95475173e7#file-smart_proxy_development-md
Restart:
Check all DB table ID fields to make sure those are migrated to bigint.