-
Notifications
You must be signed in to change notification settings - Fork 2
Automatically create all indexes for all columns for any created table #11
Copy link
Copy link
Open
Description
Lines 10 to 30 in 6accb03
| export const up = async ({ | |
| api, SCHEMA = DEFAULT_SCHEMA, MP_TABLE = DEFAULT_MP_TABLE, ID_TYPE = DEFAULT_ID_TYPE_SQL, customColumns = '' | |
| }: { | |
| api: HasuraApi; | |
| SCHEMA?: string; MP_TABLE?: string; ID_TYPE?: string; customColumns: string; | |
| }) => { | |
| await api.sql(sql` | |
| CREATE TABLE ${SCHEMA}."${MP_TABLE}" (id ${ID_TYPE} PRIMARY KEY,item_id ${ID_TYPE},path_item_id ${ID_TYPE},path_item_depth ${ID_TYPE},root_id ${ID_TYPE},position_id text DEFAULT ${SCHEMA}.gen_random_uuid(),group_id ${ID_TYPE},insert_category TEXT${customColumns}); | |
| CREATE SEQUENCE ${SCHEMA}.${MP_TABLE}_id_seq | |
| AS ${ID_TYPE} START WITH 1 INCREMENT BY 1 NO MINVALUE NO MAXVALUE CACHE 1; | |
| ALTER SEQUENCE ${SCHEMA}.${MP_TABLE}_id_seq OWNED BY ${SCHEMA}.${MP_TABLE}.id; | |
| ALTER TABLE ONLY ${SCHEMA}.${MP_TABLE} ALTER COLUMN id SET DEFAULT nextval('${SCHEMA}.${MP_TABLE}_id_seq'::regclass); | |
| `); | |
| await api.query({ | |
| type: 'track_table', | |
| args: { | |
| schema: SCHEMA, | |
| name: MP_TABLE, | |
| }, | |
| }); | |
| }; |
We can execute this function here:
https://gist.github.com/Konard/8d2866bcc55192aa24c887b40553419d
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels