mirror of
https://github.com/trailbaseio/trailbase.git
synced 2026-05-04 15:40:01 -05:00
Fix accidental submit and default values for create column presets. Also add UUIDv4 preset. #98
This commit is contained in:
@@ -505,6 +505,7 @@ export function ColumnSubForm(props: {
|
||||
{([name, preset]) => (
|
||||
<ButtonBadge
|
||||
class="p-1 active:scale-90"
|
||||
type="button"
|
||||
onClick={() => {
|
||||
const columns = [...props.form.state.values.columns];
|
||||
const column = columns[props.colIndex];
|
||||
@@ -634,6 +635,7 @@ export function PrimaryKeyColumnSubForm(props: {
|
||||
{([name, preset]) => (
|
||||
<ButtonBadge
|
||||
class="p-1 active:scale-90"
|
||||
type="button"
|
||||
onClick={() => {
|
||||
const columns = [
|
||||
...props.form.state.values.columns,
|
||||
@@ -721,6 +723,32 @@ type Preset = {
|
||||
};
|
||||
|
||||
export const primaryKeyPresets: [string, (colName: string) => Preset][] = [
|
||||
[
|
||||
"INTEGER",
|
||||
(_colName: string) => {
|
||||
return {
|
||||
data_type: "Integer",
|
||||
options: [
|
||||
{ Unique: { is_primary: true, conflict_clause: null } },
|
||||
"NotNull",
|
||||
],
|
||||
};
|
||||
},
|
||||
],
|
||||
[
|
||||
"UUIDv4",
|
||||
(colName: string) => {
|
||||
return {
|
||||
data_type: "Blob",
|
||||
options: [
|
||||
{ Unique: { is_primary: true, conflict_clause: null } },
|
||||
{ Check: `is_uuid(${colName})` },
|
||||
{ Default: "(uuid_v4())" },
|
||||
"NotNull",
|
||||
],
|
||||
};
|
||||
},
|
||||
],
|
||||
[
|
||||
"UUIDv7",
|
||||
(colName: string) => {
|
||||
@@ -735,18 +763,6 @@ export const primaryKeyPresets: [string, (colName: string) => Preset][] = [
|
||||
};
|
||||
},
|
||||
],
|
||||
[
|
||||
"INTEGER",
|
||||
(_colName: string) => {
|
||||
return {
|
||||
data_type: "Integer",
|
||||
options: [
|
||||
{ Unique: { is_primary: true, conflict_clause: null } },
|
||||
"NotNull",
|
||||
],
|
||||
};
|
||||
},
|
||||
],
|
||||
];
|
||||
|
||||
const presets: [string, (colName: string) => Preset][] = [
|
||||
@@ -759,6 +775,19 @@ const presets: [string, (colName: string) => Preset][] = [
|
||||
};
|
||||
},
|
||||
],
|
||||
[
|
||||
"UUIDv4",
|
||||
(colName: string) => {
|
||||
return {
|
||||
data_type: "Blob",
|
||||
options: [
|
||||
{ Check: `is_uuid(${colName})` },
|
||||
{ Default: "(uuid_v4())" },
|
||||
"NotNull",
|
||||
],
|
||||
};
|
||||
},
|
||||
],
|
||||
[
|
||||
"UUIDv7",
|
||||
(colName: string) => {
|
||||
@@ -779,7 +808,7 @@ const presets: [string, (colName: string) => Preset][] = [
|
||||
data_type: "Text",
|
||||
options: [
|
||||
{ Check: `is_json(${colName})` },
|
||||
{ Default: "{}" },
|
||||
{ Default: "'{}'" },
|
||||
"NotNull",
|
||||
],
|
||||
};
|
||||
@@ -807,7 +836,7 @@ const presets: [string, (colName: string) => Preset][] = [
|
||||
{
|
||||
Check: `jsonschema('std.FileUploads', ${colName})`,
|
||||
},
|
||||
{ Default: "[]" },
|
||||
{ Default: "'[]'" },
|
||||
"NotNull",
|
||||
],
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user