CREATE USER ${PG__USER}; CREATE DATABASE ${PG__DBNAME} WITH OWNER ${PG__USER}; \c ${PG__DBNAME} REVOKE ALL ON SCHEMA public FROM PUBLIC; CREATE EXTENSION postgis CASCADE; CREATE EXTENSION postgis_sfcgal CASCADE; -- TODO: https://heterodb.github.io/pg-strom/install/ -- GPU batching of PSQL queries -- CREATE EXTENSION pg_strom CASCADE; SET search_path TO "$${u}user", ${PG__DBNAME}, postgis, topology, public; ALTER ROLE ${PG__USER} SET search_path TO "$${u}user", ${PG__DBNAME}, postgis, topology, public; CREATE TABLE IF NOT EXISTS particle_types ( "id" SERIAL UNIQUE NOT NULL, "name" VARCHAR(50) UNIQUE NOT NULL, "symbol" VARCHAR(10) UNIQUE NOT NULL, "mass_kg" NUMERIC NOT NULL, "binding_energy_mev" NUMERIC DEFAULT 0.0 ); CREATE TABLE IF NOT EXISTS particles ( "type_id" INTEGER NOT NULL REFERENCES particle_types ("id"), "position" GEOMETRY NOT NULL, "orientation" GEOMETRY NOT NULL, "velocity" GEOMETRY NOT NULL, -- "energy" 0.5*mass*velocity^2 ); CREATE INDEX IF NOT EXISTS "particle_index" ON particles USING GIST ("position"); CREATE TABLE IF NOT EXISTS magnetic_fields ( "current_geometry" GEOMETRY NOT NULL, "teslas" NUMERIC NOT NULL ); INSERT INTO particle_types ("name", "symbol", "mass_kg", "binding_energy_mev") VALUES ('Electron', 'e-', 9.10938356e-31, 0.0), ('Proton', 'p+', 1.6726219e-27, 0.0), ('Neutron', 'n', 1.674927471e-27, 0.0), ('Deuterium', 'D', 3.343583719e-27, 2.224), ('Tritium', 'T', 5.0073567446e-27, 8.482), ('Helium-3', 'He3', 5.0082626e-27, 7.718058), ('Helium-4', 'He4', 6.6464764e-27, 28.295674), ('Lithium-6', 'Li6', 1.167262e-26, 31.99), ('Lithium-7', 'Li7', 1.167262e-26, 39.25); GRANT ALL PRIVILEGES ON DATABASE hearth TO calcifer; GRANT ALL PRIVILEGES ON ALL TABLES IN SCHEMA public TO calcifer;