From 5bbe585c8c203566f5b0358b216d1ee195b1d3b1 Mon Sep 17 00:00:00 2001 From: Peter Amiri Date: Mon, 16 Mar 2026 06:47:44 -0700 Subject: [PATCH] Fix CockroachDB primary key generation using unique_rowid() instead of SERIAL CockroachDB does not support PostgreSQL's SERIAL type. Override addPrimaryKeyOptions in CockroachDBMigrator to use INT DEFAULT unique_rowid() for auto-increment primary keys. Fixes #1970 Co-Authored-By: Claude Opus 4.6 --- .../CockroachDB/CockroachDBMigrator.cfc | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/vendor/wheels/databaseAdapters/CockroachDB/CockroachDBMigrator.cfc b/vendor/wheels/databaseAdapters/CockroachDB/CockroachDBMigrator.cfc index 805e8dd536..6714fe046b 100644 --- a/vendor/wheels/databaseAdapters/CockroachDB/CockroachDBMigrator.cfc +++ b/vendor/wheels/databaseAdapters/CockroachDB/CockroachDBMigrator.cfc @@ -7,4 +7,16 @@ component extends="wheels.databaseAdapters.PostgreSQL.PostgreSQLMigrator" { return "CockroachDB"; } + /** + * generates sql for primary key options + * CockroachDB does not support SERIAL; use INT DEFAULT unique_rowid() instead + */ + public string function addPrimaryKeyOptions(required string sql, struct options = {}) { + if (StructKeyExists(arguments.options, "autoIncrement") && arguments.options.autoIncrement) { + arguments.sql = ReplaceNoCase(arguments.sql, "INTEGER", "INT DEFAULT unique_rowid()", "all"); + } + arguments.sql = arguments.sql & " PRIMARY KEY"; + return arguments.sql; + } + }