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

Upgrade crdb version in workflow #5

Merged
merged 1 commit into from
Jan 4, 2024
Merged

Upgrade crdb version in workflow #5

merged 1 commit into from
Jan 4, 2024

Conversation

Alva8756
Copy link
Contributor

@Alva8756 Alva8756 commented Dec 11, 2023

Ahhh dump is deprecated on v23.1.11: https://www.cockroachlabs.com/docs/v21.1/cockroach-dump

sqlboiler auto generated code uses dump:
https://github.com/metal-toolbox/fleetdb/blob/main/internal/models/crdb_main_test.go#L69

Test is failing because of it.

@Alva8756 Alva8756 force-pushed the upgrade-crdb-version branch 4 times, most recently from 6edfbbc to 69ad583 Compare December 12, 2023 08:01
@Alva8756 Alva8756 changed the title Upgrade crdb version in workflow [WIP] Upgrade crdb version in workflow Dec 12, 2023
@Alva8756 Alva8756 force-pushed the upgrade-crdb-version branch 2 times, most recently from 75db885 to 569142e Compare December 14, 2023 05:33
@Alva8756
Copy link
Contributor Author

Alva8756 commented Dec 14, 2023

Hi @DoctorVin ,
Currently I am having 2 issues upgrading crdb version in tests.
The test itself is simple.

  1. make testdabase generates tables in db
  2. dump tables generate CREATE TABLE
  3. create tables in another DB with CREATE TABLE above.
  • dumpCmd Error:
    $ cockroach dump serverservice_test --url postgresql://root@localhost:26257/serverservice_test?sslmode=disable --insecure --dump-mode=schema

Our existing tests uses dump which is deprecated on v23.1.11: https://www.cockroachlabs.com/docs/v21.1/cockroach-dump. I am planning to replace it with SHOW CREATE ALL TABLES;
However, these test files are auto generated. I don't feel it's correct way to modify generated code directly. (It's strange that no one report such issues to sqlboiler...)

  • createCmd Error
    $ stdout from last dump cmd | cockroach sql --url postgresql://root@localhost:26257/[dbname]?sslmode=disable --database [dbname] --insecure

I am not sure what's happening here. Our new 000001_init.sql works well when I run command above locally(crdb-v23.1.11).
What's interesting is I copy/paste the result of cockroach and try it in a local crdb-v23.1.11, it can create tables successfully too.

I am guessing it's sqlboiler missing something again which leads to incompatible with latest crdb... Still needs investigation.

Anyway, since the latest crdb works well locally. I will de-prioritize upgrading crdb on tests. I'll start working on using latest crdb + fleetdb on sandbox.


$ cockroach_v21_1_21 dump serverservice_test --url postgresql://root@localhost:26257/serverservice_test --insecure --dump-mode=schema

CREATE TABLE public.goose_db_version (
        id INT8 NOT NULL DEFAULT unique_rowid(),
        version_id INT8 NOT NULL,
        is_applied BOOL NOT NULL,
        tstamp TIMESTAMP NULL DEFAULT now():::TIMESTAMP,
        CONSTRAINT goose_db_version_pkey PRIMARY KEY (id ASC)
);
CREATE TABLE public.servers (
        id UUID NOT NULL DEFAULT gen_random_uuid(),
        name STRING NULL,
        facility_code STRING NULL,
        created_at TIMESTAMPTZ NULL,
        updated_at TIMESTAMPTZ NULL,
        deleted_at TIMESTAMPTZ NULL,
        CONSTRAINT "primary" PRIMARY KEY (id ASC),
        INDEX idx_facility (facility_code ASC)
);
CREATE TABLE public.server_component_types (
        id UUID NOT NULL DEFAULT gen_random_uuid(),
        name STRING NOT NULL,
        created_at TIMESTAMPTZ NULL,
        updated_at TIMESTAMPTZ NULL,
        slug STRING NOT NULL,
        CONSTRAINT "primary" PRIMARY KEY (id ASC),
        UNIQUE INDEX idx_name (name ASC),
        UNIQUE INDEX server_component_types_slug_key (slug ASC)
);
CREATE TABLE public.server_components (
        id UUID NOT NULL DEFAULT gen_random_uuid(),
        name STRING NULL,
        vendor STRING NULL,
        model STRING NULL,
        serial STRING NULL,
        server_component_type_id UUID NOT NULL,
        server_id UUID NOT NULL,
        created_at TIMESTAMPTZ NULL,
        updated_at TIMESTAMPTZ NULL,
        CONSTRAINT "primary" PRIMARY KEY (id ASC),
        INDEX idx_server_component_type_id (server_component_type_id ASC),
        INDEX idx_server_id (server_id ASC),
        UNIQUE INDEX idx_server_components (server_id ASC, serial ASC, server_component_type_id ASC) WHERE ((server_id IS NOT NULL) AND (serial IS NOT NULL)) AND (server_component_type_id IS NOT NULL)
);
CREATE TABLE public.versioned_attributes (
        id UUID NOT NULL DEFAULT gen_random_uuid(),
        server_id UUID NULL,
        namespace STRING NOT NULL,
        data JSONB NOT NULL,
        created_at TIMESTAMPTZ NULL,
        updated_at TIMESTAMPTZ NULL,
        server_component_id UUID NULL,
        tally INT8 NOT NULL DEFAULT 0:::INT8,
        CONSTRAINT "primary" PRIMARY KEY (id ASC),
        INDEX idx_server_id (server_id ASC) WHERE server_id IS NOT NULL,
        INDEX idx_server_namespace (server_id ASC, namespace ASC, created_at ASC) WHERE server_id IS NOT NULL,
        INVERTED INDEX idx_server_data (server_id ASC, namespace ASC, data) WHERE server_id IS NOT NULL,
        INDEX idx_server_component_id (server_component_id ASC) WHERE server_component_id IS NOT NULL,
        INDEX idx_server_component_namespace (server_component_id ASC, namespace ASC, created_at ASC) WHERE server_component_id IS NOT NULL,
        INVERTED INDEX idx_server_component_data (server_component_id ASC, namespace ASC, data) WHERE server_component_id IS NOT NULL
);
CREATE TABLE public.attributes (
        id UUID NOT NULL DEFAULT gen_random_uuid(),
        server_id UUID NULL,
        server_component_id UUID NULL,
        namespace STRING NOT NULL,
        data JSONB NOT NULL,
        created_at TIMESTAMPTZ NULL,
        updated_at TIMESTAMPTZ NULL,
        CONSTRAINT "primary" PRIMARY KEY (id ASC),
        INDEX idx_server_id (server_id ASC) WHERE server_id IS NOT NULL,
        UNIQUE INDEX idx_server_namespace (server_id ASC, namespace ASC) WHERE server_id IS NOT NULL,
        INVERTED INDEX idx_server_data (server_id ASC, namespace ASC, data) WHERE server_id IS NOT NULL,
        INDEX idx_server_component_id (server_component_id ASC) WHERE server_component_id IS NOT NULL,
        UNIQUE INDEX idx_server_component_namespace (server_component_id ASC, namespace ASC) WHERE server_component_id IS NOT NULL,
        INVERTED INDEX idx_server_component_data (server_component_id ASC, namespace ASC, data) WHERE server_component_id IS NOT NULL
);
CREATE TABLE public.component_firmware_version (
        id UUID NOT NULL DEFAULT gen_random_uuid(),
        component STRING NOT NULL,
        vendor STRING NOT NULL,
        model STRING[] NOT NULL,
        filename STRING NOT NULL,
        version STRING NOT NULL,
        checksum STRING NOT NULL,
        upstream_url STRING NOT NULL,
        repository_url STRING NOT NULL,
        created_at TIMESTAMPTZ NULL,
        updated_at TIMESTAMPTZ NULL,
        CONSTRAINT "primary" PRIMARY KEY (id ASC),
        UNIQUE INDEX vendor_component_version_filename_unique (vendor ASC, component ASC, version ASC, filename ASC)
);
CREATE TABLE public.server_credential_types (
        id UUID NOT NULL DEFAULT gen_random_uuid(),
        name STRING NOT NULL,
        slug STRING NOT NULL,
        builtin BOOL NOT NULL DEFAULT false,
        created_at TIMESTAMPTZ NOT NULL,
        updated_at TIMESTAMPTZ NOT NULL,
        CONSTRAINT "primary" PRIMARY KEY (id ASC),
        UNIQUE INDEX server_secret_types_slug_key (slug ASC)
);
CREATE TABLE public.server_credentials (
        id UUID NOT NULL DEFAULT gen_random_uuid(),
        server_id UUID NOT NULL,
        server_credential_type_id UUID NOT NULL,
        password STRING NOT NULL,
        created_at TIMESTAMPTZ NOT NULL,
        updated_at TIMESTAMPTZ NOT NULL,
        username STRING NOT NULL,
        CONSTRAINT "primary" PRIMARY KEY (id ASC),
        UNIQUE INDEX idx_server_secrets_by_type (server_id ASC, server_credential_type_id ASC)
);
CREATE TABLE public.component_firmware_set (
        id UUID NOT NULL DEFAULT gen_random_uuid(),
        name STRING NOT NULL,
        created_at TIMESTAMPTZ NULL,
        updated_at TIMESTAMPTZ NULL,
        CONSTRAINT "primary" PRIMARY KEY (id ASC),
        UNIQUE INDEX idx_name (name ASC)
);
CREATE TABLE public.component_firmware_set_map (
        id UUID NOT NULL DEFAULT gen_random_uuid(),
        firmware_set_id UUID NOT NULL,
        firmware_id UUID NOT NULL,
        CONSTRAINT "primary" PRIMARY KEY (id ASC),
        UNIQUE INDEX component_firmware_set_map_firmware_set_id_firmware_id_key (firmware_set_id ASC, firmware_id ASC)
);
CREATE TABLE public.attributes_firmware_set (
        id UUID NOT NULL DEFAULT gen_random_uuid(),
        firmware_set_id UUID NULL,
        namespace STRING NOT NULL,
        data JSONB NOT NULL,
        created_at TIMESTAMPTZ NULL,
        updated_at TIMESTAMPTZ NULL,
        CONSTRAINT "primary" PRIMARY KEY (id ASC),
        INDEX idx_firmware_set_id (firmware_set_id ASC) WHERE firmware_set_id IS NOT NULL,
        INVERTED INDEX idx_firmware_set_data (firmware_set_id ASC, namespace ASC, data) WHERE firmware_set_id IS NOT NULL,
        UNIQUE INDEX idx_firmware_set_namespace (firmware_set_id ASC, namespace ASC) WHERE firmware_set_id IS NOT NULL
);
CREATE TABLE public.bom_info (
        serial_num STRING NOT NULL,
        aoc_mac_address STRING NULL,
        bmc_mac_address STRING NULL,
        num_defi_pmi STRING NULL,
        num_def_pwd STRING NULL,
        metro STRING NULL,
        CONSTRAINT "primary" PRIMARY KEY (serial_num ASC)
);
CREATE TABLE public.aoc_mac_address (
        aoc_mac_address STRING NOT NULL,
        serial_num STRING NOT NULL,
        CONSTRAINT "primary" PRIMARY KEY (aoc_mac_address ASC)
);
CREATE TABLE public.bmc_mac_address (
        bmc_mac_address STRING NOT NULL,
        serial_num STRING NOT NULL,
        CONSTRAINT "primary" PRIMARY KEY (bmc_mac_address ASC)
);
ALTER TABLE public.server_components ADD CONSTRAINT fk_server_component_type_id_ref_server_component_types FOREIGN KEY (server_component_type_id) REFERENCES public.server_component_types(id) NOT VALID;
ALTER TABLE public.server_components ADD CONSTRAINT fk_server_id_ref_servers FOREIGN KEY (server_id) REFERENCES public.servers(id) ON DELETE CASCADE NOT VALID;
ALTER TABLE public.versioned_attributes ADD CONSTRAINT fk_server_id_ref_servers FOREIGN KEY (server_id) REFERENCES public.servers(id) ON DELETE CASCADE NOT VALID;
ALTER TABLE public.versioned_attributes ADD CONSTRAINT fk_server_component_id_ref_server_components FOREIGN KEY (server_component_id) REFERENCES public.server_components(id) ON DELETE CASCADE NOT VALID;
ALTER TABLE public.attributes ADD CONSTRAINT fk_server_id_ref_servers FOREIGN KEY (server_id) REFERENCES public.servers(id) ON DELETE CASCADE NOT VALID;
ALTER TABLE public.attributes ADD CONSTRAINT fk_server_component_id_ref_server_components FOREIGN KEY (server_component_id) REFERENCES public.server_components(id) ON DELETE CASCADE NOT VALID;
ALTER TABLE public.server_credentials ADD CONSTRAINT fk_server_id_ref_servers FOREIGN KEY (server_id) REFERENCES public.servers(id) ON DELETE CASCADE NOT VALID;
ALTER TABLE public.server_credentials ADD CONSTRAINT fk_server_secret_type_id_ref_server_secret_types FOREIGN KEY (server_credential_type_id) REFERENCES public.server_credential_types(id) NOT VALID;
ALTER TABLE public.component_firmware_set_map ADD CONSTRAINT fk_firmware_set_id_ref_component_firmware_set FOREIGN KEY (firmware_set_id) REFERENCES public.component_firmware_set(id) ON DELETE CASCADE NOT VALID;
ALTER TABLE public.component_firmware_set_map ADD CONSTRAINT fk_firmware_id_ref_component_firmware_version FOREIGN KEY (firmware_id) REFERENCES public.component_firmware_version(id) ON DELETE RESTRICT NOT VALID;
ALTER TABLE public.attributes_firmware_set ADD CONSTRAINT fk_firmware_set_id_ref_component_firmware_set FOREIGN KEY (firmware_set_id) REFERENCES public.component_firmware_set(id) ON DELETE CASCADE NOT VALID;
ALTER TABLE public.aoc_mac_address ADD CONSTRAINT fk_serial_num_ref_bom_info FOREIGN KEY (serial_num) REFERENCES public.bom_info(serial_num) ON DELETE CASCADE NOT VALID;
ALTER TABLE public.bmc_mac_address ADD CONSTRAINT fk_serial_num_ref_bom_info FOREIGN KEY (serial_num) REFERENCES public.bom_info(serial_num) ON DELETE CASCADE NOT VALID;
-- Validate foreign key constraints. These can fail if there was unvalidated data during the SHOW CREATE ALL TABLES
ALTER TABLE public.server_components VALIDATE CONSTRAINT fk_server_component_type_id_ref_server_component_types;
ALTER TABLE public.server_components VALIDATE CONSTRAINT fk_server_id_ref_servers;
ALTER TABLE public.versioned_attributes VALIDATE CONSTRAINT fk_server_id_ref_servers;
ALTER TABLE public.versioned_attributes VALIDATE CONSTRAINT fk_server_component_id_ref_server_components;
ALTER TABLE public.attributes VALIDATE CONSTRAINT fk_server_id_ref_servers;
ALTER TABLE public.attributes VALIDATE CONSTRAINT fk_server_component_id_ref_server_components;
ALTER TABLE public.server_credentials VALIDATE CONSTRAINT fk_server_id_ref_servers;
ALTER TABLE public.server_credentials VALIDATE CONSTRAINT fk_server_secret_type_id_ref_server_secret_types;
ALTER TABLE public.component_firmware_set_map VALIDATE CONSTRAINT fk_firmware_set_id_ref_component_firmware_set;
ALTER TABLE public.component_firmware_set_map VALIDATE CONSTRAINT fk_firmware_id_ref_component_firmware_version;
ALTER TABLE public.attributes_firmware_set VALIDATE CONSTRAINT fk_firmware_set_id_ref_component_firmware_set;
ALTER TABLE public.aoc_mac_address VALIDATE CONSTRAINT fk_serial_num_ref_bom_info;
ALTER TABLE public.bmc_mac_address VALIDATE CONSTRAINT fk_serial_num_ref_bom_info;

@DoctorVin
Copy link
Contributor

I agree, we shouldn't be altering generated files by hand. I have a few ideas. Ping me in Slack when you're available.

Copy link

codecov bot commented Jan 1, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Comparison is base (bb58a27) 72.74% compared to head (24d7c78) 72.74%.

Additional details and impacted files
@@           Coverage Diff           @@
##             main       #5   +/-   ##
=======================================
  Coverage   72.74%   72.74%           
=======================================
  Files          38       38           
  Lines        3735     3735           
=======================================
  Hits         2717     2717           
  Misses        760      760           
  Partials      258      258           
Flag Coverage Δ
unittests 72.74% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@Alva8756 Alva8756 changed the title [WIP] Upgrade crdb version in workflow Upgrade crdb version in workflow Jan 1, 2024
@Alva8756
Copy link
Contributor Author

Alva8756 commented Jan 1, 2024

Really appreciate @DoctorVin for resolving the sqlboiler and test failures.
It would be good to use the new crdb for lint tests.

Copy link
Contributor

@DoctorVin DoctorVin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

@Alva8756 Alva8756 merged commit d095591 into main Jan 4, 2024
3 checks passed
@Alva8756 Alva8756 deleted the upgrade-crdb-version branch January 4, 2024 17:42
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

Successfully merging this pull request may close these issues.

2 participants