Skip to main content
Question

How to alter table to have uuid?

  • Jul 16, 2021 2:01 AM UTC
  • 2 replies
  • 18 views

iddpanganiban
Forum|alt.badge.img+1

We are trying to migrate this table from the dev server to production server, the table have a uuid as a column

2 replies

marcothesane
Forum|alt.badge.img+1
  • Participating Frequently
  • Jul 16, 2021 8:03 AM UTC

If your table is:

CREATE TABLE migrate_me (
  id        UUID NOT NULL DEFAULT UUID_GENERATE()
, fname VARCHAR(32)
, lname  VARCHAR(32)
);

Then, if you use CSV files for the migration, export all columns to CSV, create the same table on the other side and perform a normal COPY migrate_me FROM '/data/migrate_me.csv' DELIMITER ',' /* or whatever applies */[...];.

If you had no UUID at the source (I did not figure that out exactly from your question), like so:

CREATE TABLE migrate_me (
  fname VARCHAR(32)
, lname  VARCHAR(32)
);

, then also export all columns you have, create the table like so on the other side:

CREATE TABLE migrate_me (
  id        UUID NOT NULL DEFAULT UUID_GENERATE()
, fname VARCHAR(32)
, lname  VARCHAR(32)
);

, and copy the CSV file like so:

COPY migrate_me (
  fname
, lname
)
FROM '/data/migrate_me.csv' DELIMITER ','
[...]
;

iddpanganiban
Forum|alt.badge.img+1
  • Author
  • Participating Frequently
  • Jul 22, 2021 2:44 AM UTC

thanks for the response sir @marcothesane