From ef0b21e6648fc0e8d2973c8aee1604ba73e426b5 Mon Sep 17 00:00:00 2001 From: satorg Date: Thu, 2 Feb 2023 15:48:39 -0800 Subject: [PATCH] reproduce db schema bug --- .../resources/db/migration/V1__WorldSetup.sql | 34 ++++++++++--------- .../main/scala/demo/world/WorldMapping.scala | 6 ++-- .../src/main/scala/DoobieMapping.scala | 2 +- 3 files changed, 22 insertions(+), 20 deletions(-) diff --git a/demo/src/main/resources/db/migration/V1__WorldSetup.sql b/demo/src/main/resources/db/migration/V1__WorldSetup.sql index a3defe6a..565fbc7d 100644 --- a/demo/src/main/resources/db/migration/V1__WorldSetup.sql +++ b/demo/src/main/resources/db/migration/V1__WorldSetup.sql @@ -9,7 +9,9 @@ BEGIN; SET client_encoding = 'UTF8'; -CREATE TABLE city ( +CREATE SCHEMA demo + +CREATE TABLE demo.city ( id integer NOT NULL, name text NOT NULL, countrycode character(3) NOT NULL, @@ -17,7 +19,7 @@ CREATE TABLE city ( population integer NOT NULL ); -CREATE TABLE country ( +CREATE TABLE demo.country ( code character(3) NOT NULL, name text NOT NULL, continent text NOT NULL, @@ -36,14 +38,14 @@ CREATE TABLE country ( CONSTRAINT country_continent_check CHECK ((((((((continent = 'Asia'::text) OR (continent = 'Europe'::text)) OR (continent = 'North America'::text)) OR (continent = 'Africa'::text)) OR (continent = 'Oceania'::text)) OR (continent = 'Antarctica'::text)) OR (continent = 'South America'::text))) ); -CREATE TABLE countrylanguage ( +CREATE TABLE demo.countrylanguage ( countrycode character(3) NOT NULL, "language" text NOT NULL, isofficial boolean NOT NULL, percentage real NOT NULL ); -COPY city (id, name, countrycode, district, population) FROM stdin; +COPY demo.city (id, name, countrycode, district, population) FROM stdin; 1 Kabul AFG Kabol 1780000 2 Qandahar AFG Qandahar 237500 3 Herat AFG Herat 186800 @@ -4130,7 +4132,7 @@ COPY city (id, name, countrycode, district, population) FROM stdin; -- Data for Name: country; Type: TABLE DATA; Schema: public; Owner: chriskl -- -COPY country (code, name, continent, region, surfacearea, indepyear, population, lifeexpectancy, gnp, gnpold, localname, governmentform, headofstate, capital, code2) FROM stdin; +COPY demo.country (code, name, continent, region, surfacearea, indepyear, population, lifeexpectancy, gnp, gnpold, localname, governmentform, headofstate, capital, code2) FROM stdin; AFG Afghanistan Asia Southern and Central Asia 652090 1919 22720000 45.900002 5976.00 \N Afganistan/Afqanestan Islamic Emirate Mohammad Omar 1 AF NLD Netherlands Europe Western Europe 41526 1581 15864000 78.300003 371362.00 360478.00 Nederland Constitutional Monarchy Beatrix 5 NL ANT Netherlands Antilles North America Caribbean 800 \N 217000 74.699997 1941.00 \N Nederlandse Antillen Nonmetropolitan Territory of The Netherlands Beatrix 33 AN @@ -4377,7 +4379,7 @@ UMI United States Minor Outlying Islands Oceania Micronesia/Caribbean 16 \N 0 \N -- Data for Name: countrylanguage; Type: TABLE DATA; Schema: public; Owner: chriskl -- -COPY countrylanguage (countrycode, "language", isofficial, percentage) FROM stdin; +COPY demo.countrylanguage (countrycode, "language", isofficial, percentage) FROM stdin; AFG Pashto t 52.400002 NLD Dutch t 95.599998 ANT Papiamento t 86.199997 @@ -5365,23 +5367,23 @@ USA Portuguese f 0.2 \. -ALTER TABLE ONLY city +ALTER TABLE ONLY demo.city ADD CONSTRAINT city_pkey PRIMARY KEY (id); -ALTER TABLE ONLY country +ALTER TABLE ONLY demo.country ADD CONSTRAINT country_pkey PRIMARY KEY (code); -ALTER TABLE ONLY countrylanguage +ALTER TABLE ONLY demo.countrylanguage ADD CONSTRAINT countrylanguage_pkey PRIMARY KEY (countrycode, "language"); -ALTER TABLE ONLY country - ADD CONSTRAINT country_capital_fkey FOREIGN KEY (capital) REFERENCES city(id); +ALTER TABLE ONLY demo.country + ADD CONSTRAINT country_capital_fkey FOREIGN KEY (capital) REFERENCES demo.city(id); -ALTER TABLE ONLY countrylanguage - ADD CONSTRAINT countrylanguage_countrycode_fkey FOREIGN KEY (countrycode) REFERENCES country(code); +ALTER TABLE ONLY demo.countrylanguage + ADD CONSTRAINT countrylanguage_countrycode_fkey FOREIGN KEY (countrycode) REFERENCES demo.country(code); COMMIT; -ANALYZE city; -ANALYZE country; -ANALYZE countrylanguage; +ANALYZE demo.city; +ANALYZE demo.country; +ANALYZE demo.countrylanguage; diff --git a/demo/src/main/scala/demo/world/WorldMapping.scala b/demo/src/main/scala/demo/world/WorldMapping.scala index 1d550e26..e6111e80 100644 --- a/demo/src/main/scala/demo/world/WorldMapping.scala +++ b/demo/src/main/scala/demo/world/WorldMapping.scala @@ -19,7 +19,7 @@ import org.typelevel.log4cats.slf4j.Slf4jLogger trait WorldMapping[F[_]] extends DoobieMapping[F] { // #db_tables - object country extends TableDef("country") { + object country extends TableDef("demo.country") { val code = col("code", Meta[String]) val name = col("name", Meta[String]) val continent = col("continent", Meta[String]) @@ -38,7 +38,7 @@ trait WorldMapping[F[_]] extends DoobieMapping[F] { val code2 = col("code2", Meta[String]) } - object city extends TableDef("city") { + object city extends TableDef("demo.city") { val id = col("id", Meta[Int]) val countrycode = col("countrycode", Meta[String]) val name = col("name", Meta[String]) @@ -46,7 +46,7 @@ trait WorldMapping[F[_]] extends DoobieMapping[F] { val population = col("population", Meta[Int]) } - object countrylanguage extends TableDef("countrylanguage") { + object countrylanguage extends TableDef("demo.countrylanguage") { val countrycode = col("countrycode", Meta[String]) val language = col("language", Meta[String]) val isOfficial = col("isOfficial", Meta[Boolean]) diff --git a/modules/doobie-pg/src/main/scala/DoobieMapping.scala b/modules/doobie-pg/src/main/scala/DoobieMapping.scala index 86142781..ceb425cf 100644 --- a/modules/doobie-pg/src/main/scala/DoobieMapping.scala +++ b/modules/doobie-pg/src/main/scala/DoobieMapping.scala @@ -163,6 +163,6 @@ trait DoobieMappingLike[F[_]] extends Mapping[F] with SqlMappingLike[F] { new Read(codecs.map { case (_, (m, n)) => (m.get, if(n) Nullable else NoNulls) }, unsafeGet) } - fragment.query[Array[Any]](mkRead(codecs)).to[Vector].transact(transactor) + fragment.queryWithLogHandler[Array[Any]](_root_.doobie.util.log.LogHandler.jdkLogHandler)(mkRead(codecs)).to[Vector].transact(transactor) } }