How to insert specific UUID in h2 database?

I need to insert some default data into my database. I am using Spring Boot with Flyway integration. For testing, I use H2. MySQL will be used for production.

I made separate Flyway migration scripts, so I can use the database material for the default data (creating tables is done in a common script).

For MySQL, I have something like this:

INSERT INTO survey_definition (id, name, period) 
VALUES (0x2D1EBC5B7D2741979CF0E84451C5BBB1, 'disease-activity', 'P1M');

How can I do the same for H2?

I only found a function RANDOM_UUID()that works, but I need to use the famous UUID because I use it as foreign keys in further statements.

+1
source share
1 answer

, , . , 0x. H2 :

INSERT INTO survey_definition (id, name, period) 
VALUES ('2D1EBC5B7D2741979CF0E84451C5BBB1', 'disease-activity', 'P1M');

- (, uuid), :

INSERT INTO survey_definition (id, name, period) 
VALUES (uuid('2D1EBC5B7D2741979CF0E84451C5BBB1'), 'disease-activity', 'P1M');
+1

Source: https://habr.com/ru/post/1663576/


All Articles