mirror of
https://github.com/better-auth/better-auth.git
synced 2026-10-22 15:59:56 -05:00
Merge branch 'canary' into tunis
This commit is contained in:
@@ -117,7 +117,7 @@ export function DocsSidebar() {
|
||||
}}
|
||||
>
|
||||
<section.Icon className="size-4.5" />
|
||||
<span className="grow">{section.title}</span>
|
||||
<span className="grow tracking-normal">{section.title}</span>
|
||||
<ChevronDownIcon
|
||||
className={cn(
|
||||
"h-4 w-4 shrink-0 text-muted-foreground transition-transform duration-200",
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import { DatabaseSync } from "node:sqlite";
|
||||
import type { BetterAuthOptions } from "@better-auth/core";
|
||||
import { CamelCasePlugin, Kysely, PostgresDialect } from "kysely";
|
||||
import { Pool } from "pg";
|
||||
@@ -402,7 +403,6 @@ describe.runIf(isPostgresAvailable)("PostgreSQL Column Additions", () => {
|
||||
},
|
||||
];
|
||||
const { toBeAdded, toBeCreated } = await getMigrations(config);
|
||||
console.log(toBeAdded);
|
||||
expect(toBeCreated.length).toBe(0);
|
||||
expect(toBeAdded.length).toBe(2);
|
||||
expect(toBeAdded).toEqual(
|
||||
@@ -422,4 +422,82 @@ describe.runIf(isPostgresAvailable)("PostgreSQL Column Additions", () => {
|
||||
]),
|
||||
);
|
||||
});
|
||||
|
||||
/**
|
||||
* @see https://github.com/better-auth/better-auth/issues/8536
|
||||
*/
|
||||
it("should generate valid PostgreSQL CREATE INDEX syntax for indexed columns added to existing tables", async () => {
|
||||
const config: BetterAuthOptions = {
|
||||
database: schemaPool,
|
||||
emailAndPassword: {
|
||||
enabled: true,
|
||||
},
|
||||
};
|
||||
|
||||
const initial = await getMigrations(config);
|
||||
await initial.runMigrations();
|
||||
|
||||
config.plugins = [
|
||||
{
|
||||
id: "test-index",
|
||||
schema: {
|
||||
user: {
|
||||
fields: {
|
||||
externalId: {
|
||||
type: "string",
|
||||
index: true,
|
||||
required: false,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
];
|
||||
|
||||
const { compileMigrations } = await getMigrations(config);
|
||||
const sql = (await compileMigrations()).toLowerCase();
|
||||
|
||||
expect(sql).toContain("create index");
|
||||
expect(sql).not.toContain("add index");
|
||||
});
|
||||
});
|
||||
|
||||
/**
|
||||
* @see https://github.com/better-auth/better-auth/issues/8536
|
||||
*/
|
||||
describe("index generation for columns added to existing tables", () => {
|
||||
it("should use CREATE INDEX when adding indexed columns to existing SQLite tables", async () => {
|
||||
const config: BetterAuthOptions = {
|
||||
database: new DatabaseSync(":memory:"),
|
||||
emailAndPassword: {
|
||||
enabled: true,
|
||||
},
|
||||
};
|
||||
|
||||
const initial = await getMigrations(config);
|
||||
await initial.runMigrations();
|
||||
|
||||
config.plugins = [
|
||||
{
|
||||
id: "test-index",
|
||||
schema: {
|
||||
user: {
|
||||
fields: {
|
||||
externalId: {
|
||||
type: "string",
|
||||
index: true,
|
||||
required: false,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
];
|
||||
|
||||
const { compileMigrations } = await getMigrations(config);
|
||||
const sql = (await compileMigrations()).toLowerCase();
|
||||
|
||||
expect(sql).toContain("create index");
|
||||
expect(sql).not.toContain("add index");
|
||||
});
|
||||
});
|
||||
|
||||
@@ -9,7 +9,6 @@ import { createLogger } from "@better-auth/core/env";
|
||||
import type { KyselyDatabaseType } from "@better-auth/kysely-adapter";
|
||||
import { createKyselyAdapter } from "@better-auth/kysely-adapter";
|
||||
import type {
|
||||
AlterTableBuilder,
|
||||
AlterTableColumnAlteringBuilder,
|
||||
ColumnDataType,
|
||||
CreateIndexBuilder,
|
||||
@@ -279,7 +278,6 @@ export async function getMigrations(config: BetterAuthOptions) {
|
||||
|
||||
const migrations: (
|
||||
| AlterTableColumnAlteringBuilder
|
||||
| ReturnType<AlterTableBuilder["addIndex"]>
|
||||
| CreateTableBuilder<string, string>
|
||||
| CreateIndexBuilder
|
||||
)[] = [];
|
||||
@@ -431,10 +429,12 @@ export async function getMigrations(config: BetterAuthOptions) {
|
||||
const builder = db.schema.alterTable(table.table);
|
||||
|
||||
if (field.index) {
|
||||
const index = db.schema
|
||||
.alterTable(table.table)
|
||||
.addIndex(`${table.table}_${fieldName}_idx`);
|
||||
migrations.push(index);
|
||||
const indexName = `${table.table}_${fieldName}_${field.unique ? "uidx" : "idx"}`;
|
||||
const indexBuilder = db.schema
|
||||
.createIndex(indexName)
|
||||
.on(table.table)
|
||||
.columns([fieldName]);
|
||||
migrations.push(field.unique ? indexBuilder.unique() : indexBuilder);
|
||||
}
|
||||
|
||||
const built = builder.addColumn(fieldName, type, (col) => {
|
||||
|
||||
Generated
+440
-279
File diff suppressed because it is too large
Load Diff
+1
-1
@@ -11,7 +11,7 @@ catalog:
|
||||
'@better-auth/utils': 0.3.1
|
||||
'@better-fetch/fetch': 1.1.21
|
||||
better-call: 2.0.2
|
||||
tsdown: 0.21.0-beta.2
|
||||
tsdown: 0.21.1
|
||||
typescript: ^5.9.3
|
||||
|
||||
catalogs:
|
||||
|
||||
Reference in New Issue
Block a user