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

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 #13586

Open
1 task done
ConorWebb96 opened this issue May 2, 2024 · 3 comments
Labels
bb-data-ui bb-sql enhancement New feature or request env - production Bug found in production externaldb Relating to datasource plus firestorm Data/Infra/Revenue Team premium-enterprise Feature for Enterprise plan

Comments

@ConorWebb96
Copy link
Contributor

ConorWebb96 commented May 2, 2024

Checklist

  • 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 ConorWebb96 added bug Something isn't working bb-sql premium-enterprise Feature for Enterprise plan externaldb Relating to datasource plus env - production Bug found in production firestorm Data/Infra/Revenue Team labels May 2, 2024
@aptkingston
Copy link
Member

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.

@andz-bb andz-bb changed the title Altering a external data sources primary key causes the _id and _rev number to become disabled. Altering a external data source's primary key causes the _id and _rev number to become disabled. May 7, 2024
@andz-bb andz-bb added the bb-data-ui label May 7, 2024 — with Linear
@shogunpurple shogunpurple changed the title Altering a external data source's primary key causes the _id and _rev number to become disabled. Altering a external data source's primary key causes the _id and _rev number to become disabled - allow May 8, 2024
@shogunpurple shogunpurple removed the bug Something isn't working label May 8, 2024
@shogunpurple shogunpurple added the enhancement New feature or request label May 8, 2024 — with Linear
@shogunpurple shogunpurple changed the title Altering a external data source's primary key causes the _id and _rev number to become disabled - allow 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 May 8, 2024
@shogunpurple shogunpurple added the bug Something isn't working label May 8, 2024 — with Linear
@shogunpurple shogunpurple removed the bug Something isn't working label May 8, 2024
Copy link
Contributor Author

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bb-data-ui bb-sql enhancement New feature or request env - production Bug found in production externaldb Relating to datasource plus firestorm Data/Infra/Revenue Team premium-enterprise Feature for Enterprise plan
Projects
None yet
Development

No branches or pull requests

4 participants