Skip to the content.

int_pk2uuid_pk

Convert primary keys integer or bigint to UUID

By Clayton Boneli

ATENCION: backup your data before use this software

Some database the primary keys and related foreign keys are defined as numeric sequentials (integers), however in the world of cloud applications, the use of integers is not the default. The work of changing primary / foreign keys from whole numeric column to UUID column is made easier by using a tool that does these transformations. The goal of this project is to create a tool that transforms primary / foreign keys to UUID columns.

Limitations:

How to use:

from replace_id import IdReplacer


class MyReplacer(IdReplacer):
    def set_up(self, connection, *args, **kwargs):
        utils = kwargs['utils']
        sql = "create extension if not exists pgcrypto;"
        utils.execute(connection, sql)


MyReplacer().execute(
    params={
        'host': 'localhost',
        'port': '5432',
        'user': 'postgres',
        'password': 'postgres',
        'schema': 'public',
        'db_name': 'clayton',
        'serial_name': 'serial_id',
        'autocommit': True,
    }
)

Actions in the database

The following actions are performed on each of the tables that will have their PK / FK columns changed from integer / bigint to UUID: