budibase
budibase copied to clipboard
Altering a external data source's primary key causes the _id and _rev number to become disabled - allow budibase to notify the user when their DB schema has deviated from the one currently stored
Checklist
- [X] I have searched budibase discussions and github issues to check if my issue already exists
Hosting
- Self
- Method: docker compose
- Budibase Version: 2.24.0
- App Version: 2.24.0
Describe the bug
When changing the primary key of an external data table e.g. Postgres via an alter statement the _id
and _rev
fields are grayed out. This happens in the data area, when trying to copy either of these values from a row.
To Reproduce Steps to reproduce the behavior:
- Go to any external table
- Alter the primary key with an SQL statement
- Go back to the table
- See error, see that the fields are grayed out and can't be copied
Expected behavior
You should be able to copy the _id
and _rev
even after a table SQL alter on the primary key has happened.
Screenshots
SQL schema
CREATE TABLE "public"."timezone" (
"id" int4 NOT NULL DEFAULT nextval('timezone_id_seq'::regclass),
"name" varchar(255) NOT NULL,
"created_at" timestamptz NOT NULL DEFAULT now(),
"updated_at" timestamptz NOT NULL DEFAULT now(),
"User" text,
"birthday" timestamptz,
PRIMARY KEY ("id")
);
-- change primary key after initial create.
ALTER TABLE "public"."timezone" DROP CONSTRAINT timezone_pkey;
ALTER TABLE "public"."timezone" ALTER COLUMN "id" TYPE varchar(10);
CREATE SEQUENCE timezone_id_seq START 1;
UPDATE "public"."timezone" SET "id" = 'TM-' || LPAD(nextval('timezone_id_seq')::TEXT, 6, '0');
ALTER TABLE "public"."timezone" ADD PRIMARY KEY ("id");
This looks like a symptom of a higher level issue, because those options only get disabled when it thinks you aren't using a datasource plus. Do you still have access to the app with this issue? Would love to see the response of the network request fetching this table definition/schema.
If you use the below create script and sync the table straight into Budibase after creation it causes the _id
and _rev
options to become grayed out.
CREATE SEQUENCE user_id_seq
START WITH 1
INCREMENT BY 1
NO MINVALUE
NO MAXVALUE
CACHE 1;
CREATE TABLE users (
id VARCHAR(10) PRIMARY KEY DEFAULT ('us-' || LPAD(NEXTVAL('user_id_seq')::TEXT, 5, '0')),
name VARCHAR(100),
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);
Graying out of these options
Frontend grabbing the id, id is still accessible just seems to be a data specific issue.
Network request in the data area