mirror of
https://github.com/withastro/astro.git
synced 2024-12-30 22:03:56 -05:00
fix: remove explicit AUTOINCREMENT on int pk
This commit is contained in:
parent
05e7e0f2dd
commit
1f719ffb6d
2 changed files with 9 additions and 13 deletions
|
@ -219,11 +219,11 @@ export function hasDefault(field: DBField): field is DBFieldWithDefault {
|
|||
|
||||
function toStringDefault<T>(def: T | SQL<any>): string {
|
||||
const type = typeof def;
|
||||
if(def instanceof SQL) {
|
||||
if (def instanceof SQL) {
|
||||
return sqlite.sqlToQuery(def).sql;
|
||||
} else if(type === 'string') {
|
||||
} else if (type === 'string') {
|
||||
return sqlite.escapeString(def as string);
|
||||
} else if(type === 'boolean') {
|
||||
} else if (type === 'boolean') {
|
||||
return def ? 'TRUE' : 'FALSE';
|
||||
} else {
|
||||
return def + '';
|
||||
|
@ -233,11 +233,8 @@ function toStringDefault<T>(def: T | SQL<any>): string {
|
|||
function getDefaultValueSql(columnName: string, column: DBFieldWithDefault): string {
|
||||
switch (column.type) {
|
||||
case 'boolean':
|
||||
return toStringDefault(column.default);
|
||||
case 'number':
|
||||
return `${column.default ? toStringDefault(column.default) : 'AUTOINCREMENT'}`;
|
||||
case 'text':
|
||||
return toStringDefault(column.default);
|
||||
case 'date':
|
||||
return toStringDefault(column.default);
|
||||
case 'json': {
|
||||
|
|
|
@ -24,7 +24,7 @@ export function hasPrimaryKey(field: DBField) {
|
|||
// Exports a few common expressions
|
||||
export const NOW = sql`CURRENT_TIMESTAMP`;
|
||||
export const TRUE = sql`TRUE`;
|
||||
export const FALSE = sql`FALSE`
|
||||
export const FALSE = sql`FALSE`;
|
||||
|
||||
const dateType = customType<{ data: Date; driverData: string }>({
|
||||
dataType() {
|
||||
|
@ -105,8 +105,7 @@ function columnMapper(fieldName: string, field: DBField, isJsonSerializable: boo
|
|||
case 'number': {
|
||||
c = integer(fieldName);
|
||||
if (field.default !== undefined) c = c.default(field.default);
|
||||
// TODO: remove autoincrement per https://www.sqlite.org/autoinc.html
|
||||
if (field.primaryKey === true) c = c.primaryKey({ autoIncrement: true });
|
||||
if (field.primaryKey === true) c = c.primaryKey();
|
||||
break;
|
||||
}
|
||||
case 'boolean': {
|
||||
|
@ -132,9 +131,9 @@ function columnMapper(fieldName: string, field: DBField, isJsonSerializable: boo
|
|||
c = c.default(
|
||||
def instanceof SQL
|
||||
? def
|
||||
// default comes pre-transformed to an ISO string for D1 storage.
|
||||
: // default comes pre-transformed to an ISO string for D1 storage.
|
||||
// parse back to a Date for Drizzle.
|
||||
: z.coerce.date().parse(field.default)
|
||||
z.coerce.date().parse(field.default)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@ -152,8 +151,8 @@ function isSerializedSQL(obj: unknown): boolean {
|
|||
}
|
||||
|
||||
function convertSerializedSQL<T = unknown>(obj: T): SQL<any> | T {
|
||||
if(isSerializedSQL(obj)) {
|
||||
return new SQL((obj as any).queryChunks)
|
||||
if (isSerializedSQL(obj)) {
|
||||
return new SQL((obj as any).queryChunks);
|
||||
} else {
|
||||
return obj;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue