Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Automatically create all indexes for all columns for any created table #11

Open
Konard opened this issue Dec 5, 2021 · 0 comments
Open
Assignees

Comments

@Konard
Copy link
Member

Konard commented Dec 5, 2021

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant