Skip to content

Commit

Permalink
reproduce db schema bug
Browse files Browse the repository at this point in the history
  • Loading branch information
satorg committed Feb 2, 2023
1 parent b08d082 commit ef0b21e
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 20 deletions.
34 changes: 18 additions & 16 deletions demo/src/main/resources/db/migration/V1__WorldSetup.sql
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,17 @@ 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,
district text NOT NULL,
population integer NOT NULL
);

CREATE TABLE country (
CREATE TABLE demo.country (
code character(3) NOT NULL,
name text NOT NULL,
continent text NOT NULL,
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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;
6 changes: 3 additions & 3 deletions demo/src/main/scala/demo/world/WorldMapping.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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])
Expand All @@ -38,15 +38,15 @@ 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])
val district = col("district", Meta[String])
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])
Expand Down
2 changes: 1 addition & 1 deletion modules/doobie-pg/src/main/scala/DoobieMapping.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}

0 comments on commit ef0b21e

Please sign in to comment.