killbill-aplcache

ddl: use PostgreSQL-friendly syntax for record_id In MySQL,

7/14/2015 12:26:45 PM

Details

diff --git a/account/src/main/resources/org/killbill/billing/account/ddl.sql b/account/src/main/resources/org/killbill/billing/account/ddl.sql
index 014d23c..c29b2a8 100644
--- a/account/src/main/resources/org/killbill/billing/account/ddl.sql
+++ b/account/src/main/resources/org/killbill/billing/account/ddl.sql
@@ -2,7 +2,7 @@
 
 DROP TABLE IF EXISTS accounts;
 CREATE TABLE accounts (
-    record_id int(11) unsigned NOT NULL AUTO_INCREMENT,
+    record_id serial unique,
     id char(36) NOT NULL,
     external_key varchar(128) NULL,
     email varchar(128) DEFAULT NULL,
@@ -27,7 +27,7 @@ CREATE TABLE accounts (
     created_by varchar(50) NOT NULL,
     updated_date datetime DEFAULT NULL,
     updated_by varchar(50) DEFAULT NULL,
-    tenant_record_id int(11) unsigned default null,
+    tenant_record_id bigint unsigned not null default 0,
     PRIMARY KEY(record_id)
 ) /*! CHARACTER SET utf8 COLLATE utf8_bin */;
 CREATE UNIQUE INDEX accounts_id ON accounts(id);
@@ -36,9 +36,9 @@ CREATE INDEX accounts_tenant_record_id ON accounts(tenant_record_id);
 
 DROP TABLE IF EXISTS account_history;
 CREATE TABLE account_history (
-    record_id int(11) unsigned NOT NULL AUTO_INCREMENT,
+    record_id serial unique,
     id char(36) NOT NULL,
-    target_record_id int(11) unsigned NOT NULL,
+    target_record_id bigint unsigned not null,
     external_key varchar(128) NULL,
     email varchar(128) DEFAULT NULL,
     name varchar(100) DEFAULT NULL,
@@ -63,7 +63,7 @@ CREATE TABLE account_history (
     created_date datetime NOT NULL,
     updated_by varchar(50) NOT NULL,
     updated_date datetime NOT NULL,
-    tenant_record_id int(11) unsigned default null,
+    tenant_record_id bigint unsigned not null default 0,
     PRIMARY KEY(record_id)
 ) /*! CHARACTER SET utf8 COLLATE utf8_bin */;
 CREATE INDEX account_history_target_record_id ON account_history(target_record_id);
@@ -71,7 +71,7 @@ CREATE INDEX account_history_tenant_record_id ON account_history(tenant_record_i
 
 DROP TABLE IF EXISTS account_emails;
 CREATE TABLE account_emails (
-    record_id int(11) unsigned NOT NULL AUTO_INCREMENT,
+    record_id serial unique,
     id char(36) NOT NULL,
     account_id char(36) NOT NULL,
     email varchar(128) NOT NULL,
@@ -80,8 +80,8 @@ CREATE TABLE account_emails (
     created_date datetime NOT NULL,
     updated_by varchar(50) NOT NULL,
     updated_date datetime NOT NULL,
-    account_record_id int(11) unsigned default null,
-    tenant_record_id int(11) unsigned default null,
+    account_record_id bigint unsigned not null,
+    tenant_record_id bigint unsigned not null default 0,
     PRIMARY KEY(record_id)
 ) /*! CHARACTER SET utf8 COLLATE utf8_bin */;
 CREATE UNIQUE INDEX account_email_id ON account_emails(id);
@@ -90,9 +90,9 @@ CREATE INDEX account_emails_tenant_account_record_id ON account_emails(tenant_re
 
 DROP TABLE IF EXISTS account_email_history;
 CREATE TABLE account_email_history (
-    record_id int(11) unsigned NOT NULL AUTO_INCREMENT,
+    record_id serial unique,
     id char(36) NOT NULL,
-    target_record_id int(11) unsigned NOT NULL,
+    target_record_id bigint unsigned not null,
     account_id char(36) NOT NULL,
     email varchar(128) NOT NULL,
     is_active bool DEFAULT true,
@@ -101,8 +101,8 @@ CREATE TABLE account_email_history (
     created_date datetime NOT NULL,
     updated_by varchar(50) NOT NULL,
     updated_date datetime NOT NULL,
-    account_record_id int(11) unsigned default null,
-    tenant_record_id int(11) unsigned default null,
+    account_record_id bigint unsigned not null,
+    tenant_record_id bigint unsigned not null default 0,
     PRIMARY KEY(record_id)
 ) /*! CHARACTER SET utf8 COLLATE utf8_bin */;
 CREATE INDEX account_email_target_record_id ON account_email_history(target_record_id);
diff --git a/beatrix/src/main/resources/org/killbill/billing/beatrix/ddl.sql b/beatrix/src/main/resources/org/killbill/billing/beatrix/ddl.sql
index 2783fc6..9a64640 100644
--- a/beatrix/src/main/resources/org/killbill/billing/beatrix/ddl.sql
+++ b/beatrix/src/main/resources/org/killbill/billing/beatrix/ddl.sql
@@ -2,7 +2,7 @@
 
 DROP TABLE IF EXISTS bus_ext_events;
 CREATE TABLE bus_ext_events (
-    record_id int(11) unsigned NOT NULL AUTO_INCREMENT,
+    record_id serial unique,
     class_name varchar(128) NOT NULL,
     event_json varchar(2048) NOT NULL,
     user_token char(36),
@@ -12,8 +12,8 @@ CREATE TABLE bus_ext_events (
     processing_available_date datetime DEFAULT NULL,
     processing_state varchar(14) DEFAULT 'AVAILABLE',
     error_count int(11) unsigned DEFAULT 0,
-    search_key1 int(11) unsigned default null,
-    search_key2 int(11) unsigned default null,
+    search_key1 bigint unsigned not null,
+    search_key2 bigint unsigned not null default 0,
     PRIMARY KEY(record_id)
 ) /*! CHARACTER SET utf8 COLLATE utf8_bin */;
 CREATE INDEX  `idx_bus_ext_where` ON bus_ext_events (`processing_state`,`processing_owner`,`processing_available_date`);
@@ -21,7 +21,7 @@ CREATE INDEX bus_ext_events_tenant_account_record_id ON bus_ext_events(search_ke
 
 DROP TABLE IF EXISTS bus_ext_events_history;
 CREATE TABLE bus_ext_events_history (
-    record_id int(11) unsigned NOT NULL AUTO_INCREMENT,
+    record_id serial unique,
     class_name varchar(128) NOT NULL,
     event_json varchar(2048) NOT NULL,
     user_token char(36),
@@ -31,7 +31,7 @@ CREATE TABLE bus_ext_events_history (
     processing_available_date datetime DEFAULT NULL,
     processing_state varchar(14) DEFAULT 'AVAILABLE',
     error_count int(11) unsigned DEFAULT 0,
-    search_key1 int(11) unsigned default null,
-    search_key2 int(11) unsigned default null,
+    search_key1 bigint unsigned not null,
+    search_key2 bigint unsigned not null default 0,
     PRIMARY KEY(record_id)
 ) /*! CHARACTER SET utf8 COLLATE utf8_bin */;
diff --git a/catalog/src/main/resources/org/killbill/billing/catalog/ddl.sql b/catalog/src/main/resources/org/killbill/billing/catalog/ddl.sql
index 0bc969c..f2d11b5 100644
--- a/catalog/src/main/resources/org/killbill/billing/catalog/ddl.sql
+++ b/catalog/src/main/resources/org/killbill/billing/catalog/ddl.sql
@@ -2,13 +2,13 @@
 
 DROP TABLE IF EXISTS catalog_override_plan_definition;
 CREATE TABLE catalog_override_plan_definition (
-    record_id int(11) unsigned NOT NULL AUTO_INCREMENT,
+    record_id serial unique,
     parent_plan_name varchar(255) NOT NULL,
     effective_date datetime NOT NULL,
     is_active bool DEFAULT 1,
     created_date datetime NOT NULL,
     created_by varchar(50) NOT NULL,
-    tenant_record_id int(11) unsigned default null,
+    tenant_record_id bigint unsigned not null default 0,
     PRIMARY KEY(record_id)
 ) /*! CHARACTER SET utf8 COLLATE utf8_bin */;
 CREATE INDEX catalog_override_plan_definition_tenant_record_id ON catalog_override_plan_definition(tenant_record_id);
@@ -16,7 +16,7 @@ CREATE INDEX catalog_override_plan_definition_tenant_record_id ON catalog_overri
 
 DROP TABLE IF EXISTS catalog_override_phase_definition;
 CREATE TABLE catalog_override_phase_definition (
-    record_id int(11) unsigned NOT NULL AUTO_INCREMENT,
+    record_id serial unique,
     parent_phase_name varchar(255) NOT NULL,
     currency char(3) NOT NULL,
     fixed_price numeric(15,9) NULL,
@@ -24,20 +24,20 @@ CREATE TABLE catalog_override_phase_definition (
     effective_date datetime NOT NULL,
     created_date datetime NOT NULL,
     created_by varchar(50) NOT NULL,
-    tenant_record_id int(11) unsigned default null,
+    tenant_record_id bigint unsigned not null default 0,
     PRIMARY KEY(record_id)
 ) /*! CHARACTER SET utf8 COLLATE utf8_bin */;
 CREATE INDEX catalog_override_phase_definition_idx ON catalog_override_phase_definition(tenant_record_id, parent_phase_name, currency);
 
 DROP TABLE IF EXISTS catalog_override_plan_phase;
 CREATE TABLE catalog_override_plan_phase (
-    record_id int(11) unsigned NOT NULL AUTO_INCREMENT,
+    record_id serial unique,
     phase_number tinyint(3) unsigned NOT NULL,
-    phase_def_record_id int(11) unsigned NOT NULL,
-    target_plan_def_record_id int(11) unsigned NOT NULL,
+    phase_def_record_id bigint unsigned not null,
+    target_plan_def_record_id bigint unsigned not null,
     created_date datetime NOT NULL,
     created_by varchar(50) NOT NULL,
-    tenant_record_id int(11) unsigned default null,
+    tenant_record_id bigint unsigned not null default 0,
     PRIMARY KEY(record_id)
 ) /*! CHARACTER SET utf8 COLLATE utf8_bin */;
 CREATE INDEX catalog_override_plan_phase_idx ON catalog_override_plan_phase(tenant_record_id, phase_number, phase_def_record_id);
diff --git a/entitlement/src/main/resources/org/killbill/billing/entitlement/ddl.sql b/entitlement/src/main/resources/org/killbill/billing/entitlement/ddl.sql
index e44195e..661a4d4 100644
--- a/entitlement/src/main/resources/org/killbill/billing/entitlement/ddl.sql
+++ b/entitlement/src/main/resources/org/killbill/billing/entitlement/ddl.sql
@@ -2,7 +2,7 @@
 
 DROP TABLE IF EXISTS blocking_states;
 CREATE TABLE blocking_states (
-    record_id int(11) unsigned NOT NULL AUTO_INCREMENT,
+    record_id serial unique,
     id char(36) NOT NULL,
     blockable_id char(36) NOT NULL,
     type varchar(20) NOT NULL,
@@ -17,8 +17,8 @@ CREATE TABLE blocking_states (
     created_by varchar(50) NOT NULL,
     updated_date datetime DEFAULT NULL,
     updated_by varchar(50) DEFAULT NULL,
-    account_record_id int(11) unsigned default null,
-    tenant_record_id int(11) unsigned default null,
+    account_record_id bigint unsigned not null,
+    tenant_record_id bigint unsigned not null default 0,
     PRIMARY KEY(record_id)
 ) /*! CHARACTER SET utf8 COLLATE utf8_bin */;
 CREATE INDEX blocking_states_id ON blocking_states(blockable_id);
diff --git a/invoice/src/main/resources/org/killbill/billing/invoice/ddl.sql b/invoice/src/main/resources/org/killbill/billing/invoice/ddl.sql
index ed6f4b8..8985ac8 100644
--- a/invoice/src/main/resources/org/killbill/billing/invoice/ddl.sql
+++ b/invoice/src/main/resources/org/killbill/billing/invoice/ddl.sql
@@ -2,7 +2,7 @@
 
 DROP TABLE IF EXISTS invoice_items;
 CREATE TABLE invoice_items (
-    record_id int(11) unsigned NOT NULL AUTO_INCREMENT,
+    record_id serial unique,
     id char(36) NOT NULL,
     type varchar(24) NOT NULL,
     invoice_id char(36) NOT NULL,
@@ -21,8 +21,8 @@ CREATE TABLE invoice_items (
     linked_item_id char(36),
     created_by varchar(50) NOT NULL,
     created_date datetime NOT NULL,
-    account_record_id int(11) unsigned default null,
-    tenant_record_id int(11) unsigned default null,
+    account_record_id bigint unsigned not null,
+    tenant_record_id bigint unsigned not null default 0,
     PRIMARY KEY(record_id)
 ) /*! CHARACTER SET utf8 COLLATE utf8_bin */;
 CREATE UNIQUE INDEX invoice_items_id ON invoice_items(id);
@@ -33,7 +33,7 @@ CREATE INDEX invoice_items_tenant_account_record_id ON invoice_items(tenant_reco
 
 DROP TABLE IF EXISTS invoices;
 CREATE TABLE invoices (
-    record_id int(11) unsigned NOT NULL AUTO_INCREMENT,
+    record_id serial unique,
     id char(36) NOT NULL,
     account_id char(36) NOT NULL,
     invoice_date date NOT NULL,
@@ -42,8 +42,8 @@ CREATE TABLE invoices (
     migrated bool NOT NULL,
     created_by varchar(50) NOT NULL,
     created_date datetime NOT NULL,
-    account_record_id int(11) unsigned default null,
-    tenant_record_id int(11) unsigned default null,
+    account_record_id bigint unsigned not null,
+    tenant_record_id bigint unsigned not null default 0,
     PRIMARY KEY(record_id)
 ) /*! CHARACTER SET utf8 COLLATE utf8_bin */;
 CREATE UNIQUE INDEX invoices_id ON invoices(id);
@@ -52,7 +52,7 @@ CREATE INDEX invoices_tenant_account_record_id ON invoices(tenant_record_id, acc
 
 DROP TABLE IF EXISTS invoice_payments;
 CREATE TABLE invoice_payments (
-    record_id int(11) unsigned NOT NULL AUTO_INCREMENT,
+    record_id serial unique,
     id char(36) NOT NULL,
     type varchar(24) NOT NULL,
     invoice_id char(36) NOT NULL,
@@ -65,8 +65,8 @@ CREATE TABLE invoice_payments (
     linked_invoice_payment_id char(36) DEFAULT NULL,
     created_by varchar(50) NOT NULL,
     created_date datetime NOT NULL,
-    account_record_id int(11) unsigned default null,
-    tenant_record_id int(11) unsigned default null,
+    account_record_id bigint unsigned not null,
+    tenant_record_id bigint unsigned not null default 0,
     PRIMARY KEY(record_id)
 ) /*! CHARACTER SET utf8 COLLATE utf8_bin */;
 CREATE UNIQUE INDEX invoice_payments_id ON invoice_payments(id);
diff --git a/payment/src/main/resources/org/killbill/billing/payment/ddl.sql b/payment/src/main/resources/org/killbill/billing/payment/ddl.sql
index 0514d78..85f0e94 100644
--- a/payment/src/main/resources/org/killbill/billing/payment/ddl.sql
+++ b/payment/src/main/resources/org/killbill/billing/payment/ddl.sql
@@ -1,9 +1,8 @@
 /*! SET storage_engine=INNODB */;
 
-
 DROP TABLE IF EXISTS payment_attempts;
 CREATE TABLE payment_attempts (
-    record_id int(11) unsigned NOT NULL AUTO_INCREMENT,
+    record_id serial unique,
     id char(36) NOT NULL,
     account_id char(36) NOT NULL,
     payment_method_id char(36) DEFAULT NULL,
@@ -20,8 +19,8 @@ CREATE TABLE payment_attempts (
     created_date datetime NOT NULL,
     updated_by varchar(50) NOT NULL,
     updated_date datetime NOT NULL,
-    account_record_id int(11) unsigned DEFAULT NULL,
-    tenant_record_id int(11) unsigned DEFAULT NULL,
+    account_record_id bigint unsigned not null,
+    tenant_record_id bigint unsigned not null default 0,
     PRIMARY KEY (record_id)
 ) /*! CHARACTER SET utf8 COLLATE utf8_bin */;
 CREATE UNIQUE INDEX payment_attempts_id ON payment_attempts(id);
@@ -33,9 +32,9 @@ CREATE INDEX payment_attempts_tenant_account_record_id ON payment_attempts(tenan
 
 DROP TABLE IF EXISTS payment_attempt_history;
 CREATE TABLE payment_attempt_history (
-    record_id int(11) unsigned NOT NULL AUTO_INCREMENT,
+    record_id serial unique,
     id char(36) NOT NULL,
-    target_record_id int(11) unsigned NOT NULL,
+    target_record_id bigint unsigned not null,
     account_id char(36) NOT NULL,
     payment_method_id char(36) DEFAULT NULL,
     payment_external_key char(128) NOT NULL,
@@ -52,8 +51,8 @@ CREATE TABLE payment_attempt_history (
     created_date datetime NOT NULL,
     updated_by varchar(50) NOT NULL,
     updated_date datetime NOT NULL,
-    account_record_id int(11) unsigned DEFAULT NULL,
-    tenant_record_id int(11) unsigned DEFAULT NULL,
+    account_record_id bigint unsigned not null,
+    tenant_record_id bigint unsigned not null default 0,
     PRIMARY KEY(record_id)
 ) /*! CHARACTER SET utf8 COLLATE utf8_bin */;
 CREATE INDEX payment_attempt_history_target_record_id ON payment_attempt_history(target_record_id);
@@ -61,7 +60,7 @@ CREATE INDEX payment_attempt_history_tenant_account_record_id ON payment_attempt
 
 DROP TABLE IF EXISTS payment_methods;
 CREATE TABLE payment_methods (
-    record_id int(11) unsigned NOT NULL AUTO_INCREMENT,
+    record_id serial unique,
     id char(36) NOT NULL,
     external_key varchar(255) NOT NULL,
     account_id char(36) NOT NULL,
@@ -71,8 +70,8 @@ CREATE TABLE payment_methods (
     created_date datetime NOT NULL,
     updated_by varchar(50) NOT NULL,
     updated_date datetime NOT NULL,
-    account_record_id int(11) unsigned DEFAULT NULL,
-    tenant_record_id int(11) unsigned DEFAULT NULL,
+    account_record_id bigint unsigned not null,
+    tenant_record_id bigint unsigned not null default 0,
     PRIMARY KEY (record_id)
 ) /*! CHARACTER SET utf8 COLLATE utf8_bin */;
 CREATE UNIQUE INDEX payment_methods_id ON payment_methods(id);
@@ -83,10 +82,10 @@ CREATE INDEX payment_methods_tenant_account_record_id ON payment_methods(tenant_
 
 DROP TABLE IF EXISTS payment_method_history;
 CREATE TABLE payment_method_history (
-    record_id int(11) unsigned NOT NULL AUTO_INCREMENT,
+    record_id serial unique,
     id char(36) NOT NULL,
     external_key varchar(255) NOT NULL,
-    target_record_id int(11) unsigned NOT NULL,
+    target_record_id bigint unsigned not null,
     account_id char(36) NOT NULL,
     plugin_name varchar(50) NOT NULL,
     is_active bool DEFAULT true,
@@ -95,8 +94,8 @@ CREATE TABLE payment_method_history (
     created_date datetime NOT NULL,
     updated_by varchar(50) NOT NULL,
     updated_date datetime NOT NULL,
-    account_record_id int(11) unsigned DEFAULT NULL,
-    tenant_record_id int(11) unsigned DEFAULT NULL,
+    account_record_id bigint unsigned not null,
+    tenant_record_id bigint unsigned not null default 0,
     PRIMARY KEY(record_id)
 ) /*! CHARACTER SET utf8 COLLATE utf8_bin */;
 CREATE INDEX payment_method_history_target_record_id ON payment_method_history(target_record_id);
@@ -105,7 +104,7 @@ CREATE INDEX payment_method_history_tenant_account_record_id ON payment_method_h
 
 DROP TABLE IF EXISTS payments;
 CREATE TABLE payments (
-    record_id int(11) unsigned NOT NULL AUTO_INCREMENT,
+    record_id serial unique,
     id char(36) NOT NULL,
     account_id char(36) NOT NULL,
     payment_method_id char(36) NOT NULL,
@@ -116,8 +115,8 @@ CREATE TABLE payments (
     created_date datetime NOT NULL,
     updated_by varchar(50) NOT NULL,
     updated_date datetime NOT NULL,
-    account_record_id int(11) unsigned DEFAULT NULL,
-    tenant_record_id int(11) unsigned DEFAULT NULL,
+    account_record_id bigint unsigned not null,
+    tenant_record_id bigint unsigned not null default 0,
     PRIMARY KEY (record_id)
 ) /*! CHARACTER SET utf8 COLLATE utf8_bin */;
 CREATE UNIQUE INDEX payments_id ON payments(id);
@@ -128,9 +127,9 @@ CREATE INDEX payments_tenant_account_record_id ON payments(tenant_record_id, acc
 
 DROP TABLE IF EXISTS payment_history;
 CREATE TABLE payment_history (
-    record_id int(11) unsigned NOT NULL AUTO_INCREMENT,
+    record_id serial unique,
     id char(36) NOT NULL,
-    target_record_id int(11) unsigned NOT NULL,
+    target_record_id bigint unsigned not null,
     account_id char(36) NOT NULL,
     payment_method_id char(36) NOT NULL,
     external_key varchar(255) NOT NULL,
@@ -141,8 +140,8 @@ CREATE TABLE payment_history (
     created_date datetime NOT NULL,
     updated_by varchar(50) NOT NULL,
     updated_date datetime NOT NULL,
-    account_record_id int(11) unsigned DEFAULT NULL,
-    tenant_record_id int(11) unsigned DEFAULT NULL,
+    account_record_id bigint unsigned not null,
+    tenant_record_id bigint unsigned not null default 0,
     PRIMARY KEY(record_id)
 ) /*! CHARACTER SET utf8 COLLATE utf8_bin */;
 CREATE INDEX payment_history_target_record_id ON payment_history(target_record_id);
@@ -151,7 +150,7 @@ CREATE INDEX payment_history_tenant_account_record_id ON payment_history(tenant_
 
 DROP TABLE IF EXISTS payment_transactions;
 CREATE TABLE payment_transactions (
-    record_id int(11) unsigned NOT NULL AUTO_INCREMENT,
+    record_id serial unique,
     id char(36) NOT NULL,
     attempt_id char(36) DEFAULT NULL,
     transaction_external_key varchar(255) NOT NULL,
@@ -169,8 +168,8 @@ CREATE TABLE payment_transactions (
     created_date datetime NOT NULL,
     updated_by varchar(50) NOT NULL,
     updated_date datetime NOT NULL,
-    account_record_id int(11) unsigned DEFAULT NULL,
-    tenant_record_id int(11) unsigned DEFAULT NULL,
+    account_record_id bigint unsigned not null,
+    tenant_record_id bigint unsigned not null default 0,
     PRIMARY KEY (record_id)
 ) /*! CHARACTER SET utf8 COLLATE utf8_bin */;
 CREATE UNIQUE INDEX transactions_id ON payment_transactions(id);
@@ -181,11 +180,11 @@ CREATE INDEX transactions_tenant_account_record_id ON payment_transactions(tenan
 
 DROP TABLE IF EXISTS payment_transaction_history;
 CREATE TABLE payment_transaction_history (
-    record_id int(11) unsigned NOT NULL AUTO_INCREMENT,
+    record_id serial unique,
     id char(36) NOT NULL,
     attempt_id char(36) DEFAULT NULL,
     transaction_external_key varchar(255) NOT NULL,
-    target_record_id int(11) unsigned NOT NULL,
+    target_record_id bigint unsigned not null,
     transaction_type varchar(32) NOT NULL,
     effective_date datetime NOT NULL,
     transaction_status varchar(50) NOT NULL,
@@ -201,8 +200,8 @@ CREATE TABLE payment_transaction_history (
     created_date datetime NOT NULL,
     updated_by varchar(50) NOT NULL,
     updated_date datetime NOT NULL,
-    account_record_id int(11) unsigned DEFAULT NULL,
-    tenant_record_id int(11) unsigned DEFAULT NULL,
+    account_record_id bigint unsigned not null,
+    tenant_record_id bigint unsigned not null default 0,
     PRIMARY KEY (record_id)
 ) /*! CHARACTER SET utf8 COLLATE utf8_bin */;
 CREATE INDEX transaction_history_target_record_id ON payment_transaction_history(target_record_id);
@@ -212,7 +211,7 @@ CREATE INDEX transaction_history_tenant_account_record_id ON payment_transaction
 /*  PaymentControlPlugin lives  here until this becomes a first class citizen plugin */
 DROP TABLE IF EXISTS _invoice_payment_control_plugin_auto_pay_off;
 CREATE TABLE _invoice_payment_control_plugin_auto_pay_off (
-    record_id int(11) unsigned NOT NULL AUTO_INCREMENT,
+    record_id serial unique,
     attempt_id char(36) NOT NULL,
     payment_external_key varchar(255) NOT NULL,
     transaction_external_key varchar(255) NOT NULL,
diff --git a/subscription/src/main/resources/org/killbill/billing/subscription/ddl.sql b/subscription/src/main/resources/org/killbill/billing/subscription/ddl.sql
index 6d5b7c7..6941c04 100644
--- a/subscription/src/main/resources/org/killbill/billing/subscription/ddl.sql
+++ b/subscription/src/main/resources/org/killbill/billing/subscription/ddl.sql
@@ -2,7 +2,7 @@
 
 DROP TABLE IF EXISTS subscription_events;
 CREATE TABLE subscription_events (
-    record_id int(11) unsigned NOT NULL AUTO_INCREMENT,
+    record_id serial unique,
     id char(36) NOT NULL,
     event_type varchar(9) NOT NULL,
     user_type varchar(25) DEFAULT NULL,
@@ -18,8 +18,8 @@ CREATE TABLE subscription_events (
     created_date datetime NOT NULL,
     updated_by varchar(50) NOT NULL,
     updated_date datetime NOT NULL,
-    account_record_id int(11) unsigned default null,
-    tenant_record_id int(11) unsigned default null,
+    account_record_id bigint unsigned not null,
+    tenant_record_id bigint unsigned not null default 0,
     PRIMARY KEY(record_id)
 ) /*! CHARACTER SET utf8 COLLATE utf8_bin */;
 CREATE UNIQUE INDEX subscription_events_id ON subscription_events(id);
@@ -29,7 +29,7 @@ CREATE INDEX subscription_events_tenant_account_record_id ON subscription_events
 
 DROP TABLE IF EXISTS subscriptions;
 CREATE TABLE subscriptions (
-    record_id int(11) unsigned NOT NULL AUTO_INCREMENT,
+    record_id serial unique,
     id char(36) NOT NULL,
     bundle_id char(36) NOT NULL,
     category varchar(32) NOT NULL,
@@ -41,8 +41,8 @@ CREATE TABLE subscriptions (
     created_date datetime NOT NULL,
     updated_by varchar(50) NOT NULL,
     updated_date datetime NOT NULL,
-    account_record_id int(11) unsigned default null,
-    tenant_record_id int(11) unsigned default null,
+    account_record_id bigint unsigned not null,
+    tenant_record_id bigint unsigned not null default 0,
     PRIMARY KEY(record_id)
 ) /*! CHARACTER SET utf8 COLLATE utf8_bin */;
 CREATE UNIQUE INDEX subscriptions_id ON subscriptions(id);
@@ -51,7 +51,7 @@ CREATE INDEX subscriptions_tenant_account_record_id ON subscriptions(tenant_reco
 
 DROP TABLE IF EXISTS bundles;
 CREATE TABLE bundles (
-    record_id int(11) unsigned NOT NULL AUTO_INCREMENT,
+    record_id serial unique,
     id char(36) NOT NULL,
     external_key varchar(64) NOT NULL,
     account_id char(36) NOT NULL,
@@ -61,8 +61,8 @@ CREATE TABLE bundles (
     created_date datetime NOT NULL,
     updated_by varchar(50) NOT NULL,
     updated_date datetime NOT NULL,
-    account_record_id int(11) unsigned default null,
-    tenant_record_id int(11) unsigned default null,
+    account_record_id bigint unsigned not null,
+    tenant_record_id bigint unsigned not null default 0,
     PRIMARY KEY(record_id)
 ) /*! CHARACTER SET utf8 COLLATE utf8_bin */;
 CREATE UNIQUE INDEX bundles_id ON bundles(id);
diff --git a/tenant/src/main/resources/org/killbill/billing/tenant/ddl.sql b/tenant/src/main/resources/org/killbill/billing/tenant/ddl.sql
index d549318..d1755c5 100644
--- a/tenant/src/main/resources/org/killbill/billing/tenant/ddl.sql
+++ b/tenant/src/main/resources/org/killbill/billing/tenant/ddl.sql
@@ -2,7 +2,7 @@
 
 DROP TABLE IF EXISTS tenants;
 CREATE TABLE tenants (
-    record_id int(11) unsigned NOT NULL AUTO_INCREMENT,
+    record_id serial unique,
     id char(36) NOT NULL,
     external_key varchar(128) NULL,
     api_key varchar(128) NULL,
@@ -20,9 +20,9 @@ CREATE UNIQUE INDEX tenants_api_key ON tenants(api_key);
 
 DROP TABLE IF EXISTS tenant_kvs;
 CREATE TABLE tenant_kvs (
-   record_id int(11) unsigned NOT NULL AUTO_INCREMENT,
+   record_id serial unique,
    id char(36) NOT NULL,
-   tenant_record_id int(11) unsigned NOT NULL,
+   tenant_record_id bigint unsigned not null default 0,
    tenant_key varchar(255) NOT NULL,
    tenant_value mediumtext NOT NULL,
    is_active bool DEFAULT 1,
@@ -37,11 +37,11 @@ CREATE INDEX tenant_kvs_key ON tenant_kvs(tenant_key);
 
 DROP TABLE IF EXISTS tenant_broadcasts;
 CREATE TABLE tenant_broadcasts (
-   record_id int(11) unsigned NOT NULL AUTO_INCREMENT,
+   record_id serial unique,
    id char(36) NOT NULL,
-   target_record_id int(11) unsigned,
+   target_record_id bigint unsigned not null,
    target_table_name varchar(50) NOT NULL,
-   tenant_record_id int(11) unsigned NOT NULL,
+   tenant_record_id bigint unsigned not null default 0,
    type varchar(64) NOT NULL,
    user_token char(36),
    created_date datetime NOT NULL,
diff --git a/usage/src/main/resources/org/killbill/billing/usage/ddl.sql b/usage/src/main/resources/org/killbill/billing/usage/ddl.sql
index 3974dab..d8123c5 100644
--- a/usage/src/main/resources/org/killbill/billing/usage/ddl.sql
+++ b/usage/src/main/resources/org/killbill/billing/usage/ddl.sql
@@ -2,7 +2,7 @@
 
 DROP TABLE IF EXISTS rolled_up_usage;
 CREATE TABLE rolled_up_usage (
-    record_id int(11) unsigned NOT NULL AUTO_INCREMENT,
+    record_id serial unique,
     id char(36) NOT NULL,
     subscription_id char(36),
     unit_type varchar(50),
@@ -10,8 +10,8 @@ CREATE TABLE rolled_up_usage (
     amount bigint NOT NULL,
     created_by varchar(50) NOT NULL,
     created_date datetime NOT NULL,
-    account_record_id int(11) unsigned default null,
-    tenant_record_id int(11) unsigned default null,
+    account_record_id bigint unsigned not null,
+    tenant_record_id bigint unsigned not null default 0,
     PRIMARY KEY(record_id)
 ) /*! CHARACTER SET utf8 COLLATE utf8_bin */;
 CREATE UNIQUE INDEX rolled_up_usage_id ON rolled_up_usage(id);
diff --git a/util/src/main/resources/org/killbill/billing/util/ddl.sql b/util/src/main/resources/org/killbill/billing/util/ddl.sql
index c1482a5..4fd421d 100644
--- a/util/src/main/resources/org/killbill/billing/util/ddl.sql
+++ b/util/src/main/resources/org/killbill/billing/util/ddl.sql
@@ -2,7 +2,7 @@
 
 DROP TABLE IF EXISTS custom_fields;
 CREATE TABLE custom_fields (
-    record_id int(11) unsigned NOT NULL AUTO_INCREMENT,
+    record_id serial unique,
     id char(36) NOT NULL,
     object_id char(36) NOT NULL,
     object_type varchar(30) NOT NULL,
@@ -13,8 +13,8 @@ CREATE TABLE custom_fields (
     created_date datetime NOT NULL,
     updated_by varchar(50) DEFAULT NULL,
     updated_date datetime DEFAULT NULL,
-    account_record_id int(11) unsigned default null,
-    tenant_record_id int(11) unsigned default null,
+    account_record_id bigint unsigned not null,
+    tenant_record_id bigint unsigned not null default 0,
     PRIMARY KEY(record_id)
 ) /*! CHARACTER SET utf8 COLLATE utf8_bin */;
 CREATE UNIQUE INDEX custom_fields_id ON custom_fields(id);
@@ -23,9 +23,9 @@ CREATE INDEX custom_fields_tenant_account_record_id ON custom_fields(tenant_reco
 
 DROP TABLE IF EXISTS custom_field_history;
 CREATE TABLE custom_field_history (
-    record_id int(11) unsigned NOT NULL AUTO_INCREMENT,
+    record_id serial unique,
     id char(36) NOT NULL,
-    target_record_id int(11) unsigned NOT NULL,
+    target_record_id bigint unsigned not null,
     object_id char(36) NOT NULL,
     object_type varchar(30) NOT NULL,
     is_active bool DEFAULT true,
@@ -36,8 +36,8 @@ CREATE TABLE custom_field_history (
     created_date datetime NOT NULL,
     updated_by varchar(50) NOT NULL,
     updated_date datetime NOT NULL,
-    account_record_id int(11) unsigned default null,
-    tenant_record_id int(11) unsigned default null,
+    account_record_id bigint unsigned not null,
+    tenant_record_id bigint unsigned not null default 0,
     PRIMARY KEY(record_id)
 ) /*! CHARACTER SET utf8 COLLATE utf8_bin */;
 CREATE INDEX custom_field_history_target_record_id ON custom_field_history(target_record_id);
@@ -46,7 +46,7 @@ CREATE INDEX custom_field_history_tenant_account_record_id ON custom_field_histo
 
 DROP TABLE IF EXISTS tag_definitions;
 CREATE TABLE tag_definitions (
-    record_id int(11) unsigned NOT NULL AUTO_INCREMENT,
+    record_id serial unique,
     id char(36) NOT NULL,
     name varchar(20) NOT NULL,
     description varchar(200) NOT NULL,
@@ -55,7 +55,7 @@ CREATE TABLE tag_definitions (
     created_date datetime NOT NULL,
     updated_by varchar(50) NOT NULL,
     updated_date datetime NOT NULL,
-    tenant_record_id int(11) unsigned default null,
+    tenant_record_id bigint unsigned not null default 0,
     PRIMARY KEY(record_id)
 ) /*! CHARACTER SET utf8 COLLATE utf8_bin */;
 CREATE UNIQUE INDEX tag_definitions_id ON tag_definitions(id);
@@ -63,9 +63,9 @@ CREATE INDEX tag_definitions_tenant_record_id ON tag_definitions(tenant_record_i
 
 DROP TABLE IF EXISTS tag_definition_history;
 CREATE TABLE tag_definition_history (
-    record_id int(11) unsigned NOT NULL AUTO_INCREMENT,
+    record_id serial unique,
     id char(36) NOT NULL,
-    target_record_id int(11) unsigned NOT NULL,
+    target_record_id bigint unsigned not null,
     name varchar(30) NOT NULL,
     description varchar(200),
     is_active bool DEFAULT true,
@@ -74,8 +74,8 @@ CREATE TABLE tag_definition_history (
     created_date datetime NOT NULL,
     updated_by varchar(50) NOT NULL,
     updated_date datetime NOT NULL,
-    account_record_id int(11) unsigned default null,
-    tenant_record_id int(11) unsigned default null,
+    account_record_id bigint unsigned not null,
+    tenant_record_id bigint unsigned not null default 0,
     PRIMARY KEY(record_id)
 ) /*! CHARACTER SET utf8 COLLATE utf8_bin */;
 CREATE INDEX tag_definition_history_id ON tag_definition_history(id);
@@ -85,7 +85,7 @@ CREATE INDEX tag_definition_history_tenant_record_id ON tag_definition_history(t
 
 DROP TABLE IF EXISTS tags;
 CREATE TABLE tags (
-    record_id int(11) unsigned NOT NULL AUTO_INCREMENT,
+    record_id serial unique,
     id char(36) NOT NULL,
     tag_definition_id char(36) NOT NULL,
     object_id char(36) NOT NULL,
@@ -95,8 +95,8 @@ CREATE TABLE tags (
     created_date datetime NOT NULL,
     updated_by varchar(50) NOT NULL,
     updated_date datetime NOT NULL,
-    account_record_id int(11) unsigned default null,
-    tenant_record_id int(11) unsigned default null,
+    account_record_id bigint unsigned not null,
+    tenant_record_id bigint unsigned not null default 0,
     PRIMARY KEY(record_id)
 ) /*! CHARACTER SET utf8 COLLATE utf8_bin */;
 CREATE UNIQUE INDEX tags_id ON tags(id);
@@ -105,9 +105,9 @@ CREATE INDEX tags_tenant_account_record_id ON tags(tenant_record_id, account_rec
 
 DROP TABLE IF EXISTS tag_history;
 CREATE TABLE tag_history (
-    record_id int(11) unsigned NOT NULL AUTO_INCREMENT,
+    record_id serial unique,
     id char(36) NOT NULL,
-    target_record_id int(11) unsigned NOT NULL,
+    target_record_id bigint unsigned not null,
     object_id char(36) NOT NULL,
     object_type varchar(30) NOT NULL,
     tag_definition_id char(36) NOT NULL,
@@ -117,8 +117,8 @@ CREATE TABLE tag_history (
     created_date datetime NOT NULL,
     updated_by varchar(50) NOT NULL,
     updated_date datetime NOT NULL,
-    account_record_id int(11) unsigned default null,
-    tenant_record_id int(11) unsigned default null,
+    account_record_id bigint unsigned not null,
+    tenant_record_id bigint unsigned not null default 0,
     PRIMARY KEY(record_id)
 ) /*! CHARACTER SET utf8 COLLATE utf8_bin */;
 CREATE INDEX tag_history_target_record_id ON tag_history(target_record_id);
@@ -127,9 +127,9 @@ CREATE INDEX tag_history_tenant_account_record_id ON tag_history(tenant_record_i
 
 DROP TABLE IF EXISTS audit_log;
 CREATE TABLE audit_log (
-    record_id int(11) unsigned NOT NULL AUTO_INCREMENT,
+    record_id serial unique,
     id char(36) NOT NULL,
-    target_record_id int(11) NOT NULL,
+    target_record_id bigint unsigned not null,
     table_name varchar(50) NOT NULL,
     change_type char(6) NOT NULL,
     created_date datetime NOT NULL,
@@ -137,8 +137,8 @@ CREATE TABLE audit_log (
     reason_code varchar(255) DEFAULT NULL,
     comments varchar(255) DEFAULT NULL,
     user_token char(36),
-    account_record_id int(11) unsigned default null,
-    tenant_record_id int(11) unsigned default null,
+    account_record_id bigint unsigned not null,
+    tenant_record_id bigint unsigned not null default 0,
     PRIMARY KEY(record_id)
 ) /*! CHARACTER SET utf8 COLLATE utf8_bin */;
 CREATE INDEX audit_log_fetch_target_record_id ON audit_log(table_name, target_record_id);
@@ -150,7 +150,7 @@ CREATE INDEX audit_log_via_history ON audit_log(target_record_id, table_name, te
 
 DROP TABLE IF EXISTS notifications;
 CREATE TABLE notifications (
-    record_id int(11) unsigned NOT NULL AUTO_INCREMENT,
+    record_id serial unique,
     class_name varchar(256) NOT NULL,
     event_json varchar(2048) NOT NULL,
     user_token char(36),
@@ -160,8 +160,8 @@ CREATE TABLE notifications (
     processing_available_date datetime DEFAULT NULL,
     processing_state varchar(14) DEFAULT 'AVAILABLE',
     error_count int(11) unsigned DEFAULT 0,
-    search_key1 int(11) unsigned default null,
-    search_key2 int(11) unsigned default null,
+    search_key1 bigint unsigned not null,
+    search_key2 bigint unsigned not null default 0,
     queue_name char(64) NOT NULL,
     effective_date datetime NOT NULL,
     future_user_token char(36),
@@ -174,7 +174,7 @@ CREATE INDEX notifications_tenant_account_record_id ON notifications(search_key2
 
 DROP TABLE IF EXISTS notifications_history;
 CREATE TABLE notifications_history (
-    record_id int(11) unsigned NOT NULL AUTO_INCREMENT,
+    record_id serial unique,
     class_name varchar(256) NOT NULL,
     event_json varchar(2048) NOT NULL,
     user_token char(36),
@@ -184,8 +184,8 @@ CREATE TABLE notifications_history (
     processing_available_date datetime DEFAULT NULL,
     processing_state varchar(14) DEFAULT 'AVAILABLE',
     error_count int(11) unsigned DEFAULT 0,
-    search_key1 int(11) unsigned default null,
-    search_key2 int(11) unsigned default null,
+    search_key1 bigint unsigned not null,
+    search_key2 bigint unsigned not null default 0,
     queue_name char(64) NOT NULL,
     effective_date datetime NOT NULL,
     future_user_token char(36),
@@ -194,7 +194,7 @@ CREATE TABLE notifications_history (
 
 DROP TABLE IF EXISTS bus_events;
 CREATE TABLE bus_events (
-    record_id int(11) unsigned NOT NULL AUTO_INCREMENT,
+    record_id serial unique,
     class_name varchar(128) NOT NULL,
     event_json varchar(2048) NOT NULL,
     user_token char(36),
@@ -204,8 +204,8 @@ CREATE TABLE bus_events (
     processing_available_date datetime DEFAULT NULL,
     processing_state varchar(14) DEFAULT 'AVAILABLE',
     error_count int(11) unsigned DEFAULT 0,
-    search_key1 int(11) unsigned default null,
-    search_key2 int(11) unsigned default null,
+    search_key1 bigint unsigned not null,
+    search_key2 bigint unsigned not null default 0,
     PRIMARY KEY(record_id)
 ) /*! CHARACTER SET utf8 COLLATE utf8_bin */;
 CREATE INDEX  `idx_bus_where` ON bus_events (`processing_state`,`processing_owner`,`processing_available_date`);
@@ -213,7 +213,7 @@ CREATE INDEX bus_events_tenant_account_record_id ON bus_events(search_key2, sear
 
 DROP TABLE IF EXISTS bus_events_history;
 CREATE TABLE bus_events_history (
-    record_id int(11) unsigned NOT NULL AUTO_INCREMENT,
+    record_id serial unique,
     class_name varchar(128) NOT NULL,
     event_json varchar(2048) NOT NULL,
     user_token char(36),
@@ -223,14 +223,14 @@ CREATE TABLE bus_events_history (
     processing_available_date datetime DEFAULT NULL,
     processing_state varchar(14) DEFAULT 'AVAILABLE',
     error_count int(11) unsigned DEFAULT 0,
-    search_key1 int(11) unsigned default null,
-    search_key2 int(11) unsigned default null,
+    search_key1 bigint unsigned not null,
+    search_key2 bigint unsigned not null default 0,
     PRIMARY KEY(record_id)
 ) /*! CHARACTER SET utf8 COLLATE utf8_bin */;
 
 drop table if exists sessions;
 create table sessions (
-  record_id int(11) unsigned not null auto_increment
+  record_id serial unique
 , start_timestamp datetime not null
 , last_access_time datetime default null
 , timeout int(11)
@@ -242,7 +242,7 @@ create table sessions (
 
 DROP TABLE IF EXISTS users;
 CREATE TABLE users (
-    record_id int(11) unsigned NOT NULL AUTO_INCREMENT,
+    record_id serial unique,
     username varchar(128) NULL,
     password varchar(128) NULL,
     password_salt varchar(128) NULL,
@@ -258,7 +258,7 @@ CREATE INDEX users_username ON users(username);
 
 DROP TABLE IF EXISTS user_roles;
 CREATE TABLE user_roles (
-    record_id int(11) unsigned NOT NULL AUTO_INCREMENT,
+    record_id serial unique,
     username varchar(128) NULL,
     role_name varchar(128) NULL,
     is_active bool DEFAULT 1,
@@ -273,7 +273,7 @@ CREATE INDEX user_roles_idx ON user_roles(username, role_name);
 
 DROP TABLE IF EXISTS roles_permissions;
 CREATE TABLE roles_permissions (
-    record_id int(11) unsigned NOT NULL AUTO_INCREMENT,
+    record_id serial unique,
     role_name varchar(128) NULL,
     permission varchar(128) NULL,
     is_active bool DEFAULT 1,