Skip to content

LOG-1872 needed to fix country codes in label #210

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

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 40 additions & 0 deletions script/countries.sc
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/*
TO run from project root:
cat script/countries.sc | sbt console
*/
import io.flow.reference.data.Countries
import java.io.{FileOutputStream, PrintWriter}
def cleanStr(str: String) = str.replace("'", "''")
val writer = new PrintWriter(new FileOutputStream("./countries.sql"))
val definition =
"""
|create schema reference;
|CREATE TABLE reference.countries (
| id numeric not null primary key,
| iso31663 character varying(3) NOT NULL,
| iso31662 character varying(2) NOT NULL,
| languages JSON[],
| name text NOT NULL,
| measurement_system text,
| default_currency text,
| default_language text
|);
|""".stripMargin
writer.println(definition)
writer.flush()
val lines = Countries.all.zipWithIndex.map {
case (country, ndx) => {
val line =
s"""
|insert into reference.countries (id,iso31663,iso31662,languages,name,measurement_system,default_currency,default_language) values (${ndx + 1},'${country.iso31663}','${country.iso31662}',array[${country.languages.map(l => s"""'"${l}"'""").mkString(",")}]::json[],'${cleanStr(country.name)}','${country.measurementSystem}','${
country.defaultCurrency
.getOrElse("")
}',${country.defaultLanguage.map(dl => s"'${dl}'").getOrElse(null)});""".stripMargin
line
}
}

lines.foreach(l => writer.println(l))
writer.flush()
writer.close()