budibase icon indicating copy to clipboard operation
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

Open ConorWebb96 opened this issue 9 months ago • 3 comments

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:

  1. Go to any external table
  2. Alter the primary key with an SQL statement
  3. Go back to the table
  4. 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

Screenshot 2024-05-02 at 08 54 18

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");

ConorWebb96 avatar May 02 '24 07:05 ConorWebb96

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.

aptkingston avatar May 02 '24 10:05 aptkingston

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

Screenshot_2024-05-09_at_08.00.05.webp

Frontend grabbing the id, id is still accessible just seems to be a data specific issue.

image.png

Network request in the data area

Screenshot 2024-05-09 at 11.47.41.png

ConorWebb96 avatar May 09 '24 10:05 ConorWebb96