Skip to content

Commit

Permalink
For MySQL, add a UNIQUE constraint for non-PK generated columns.
Browse files Browse the repository at this point in the history
  • Loading branch information
vnayar committed Dec 15, 2024
1 parent 0a39615 commit 4b2cd40
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions source/hibernated/dialects/mysqldialect.d
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,12 @@ class MySQLDialect : Dialect {
bool fk = pi is null;
string nullablility = !fk && pi.nullable ? " NULL" : " NOT NULL";
string pk = !fk && pi.key ? " PRIMARY KEY" : "";
string autoinc = !fk && pi.generated ? " AUTO_INCREMENT" : "";
// MySQL only supports AUTO_INCREMENT for the primary key.
string autoinc = (!fk && pi.generated)
? (pi.key
? " AUTO_INCREMENT"
: " UNIQUE AUTO_INCREMENT")
: "";
string def = "";
int len = 0;
string unsigned = "";
Expand Down Expand Up @@ -233,4 +238,4 @@ unittest {
assert(dialect.quoteSqlString("a\nc") == "'a\\nc'");
assert(dialect.quoteIfNeeded("blabla") == "blabla");
assert(dialect.quoteIfNeeded("true") == "`true`");
}
}

0 comments on commit 4b2cd40

Please sign in to comment.