Advertisement
Guest User

Untitled

a guest
Aug 30th, 2018
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.55 KB | None | 0 0
  1. import * as pg from "pg"
  2.  
  3. const pool = new pg.Pool({
  4. database: process.env.GF_DATABASE_NAME,
  5. user: process.env.GF_DATABASE_USER,
  6. password: process.env.GF_DATABASE_PASSWORD
  7. })
  8.  
  9. async function prepare() {
  10. const client = await pool.connect()
  11. const schema = process.env.GF_DATABASE_PRIVATE_SCHEMA
  12.  
  13. await client.query(`SET search_path TO ${schema}`)
  14. await client.query(`
  15.  
  16. -- DROP TABLE IF EXISTS noblockchain_cryptomaterial;
  17. CREATE TABLE IF NOT EXISTS noblockchain_cryptomaterial (
  18. pubkey BYTEA NOT NULL,
  19. privkey BYTEA NOT null,
  20. UNIQUE (pubkey)
  21. );
  22.  
  23. DROP TABLE IF EXISTS investor CASCADE;
  24. CREATE TABLE IF NOT EXISTS investor (
  25. rowid SERIAL PRIMARY KEY,
  26. tuid text not null,
  27. email text not null,
  28. password text not null,
  29. username text not null,
  30. aux_data json not null,
  31. UNIQUE (tuid)
  32. );
  33.  
  34. DROP TABLE IF EXISTS portfolio;
  35. CREATE TABLE IF NOT EXISTS portfolio (
  36. rowid SERIAL PRIMARY KEY,
  37. tuid text not null,
  38. name text not null,
  39. owner text references investor(tuid) ON DELETE CASCADE,
  40. aux_data text not null
  41. );
  42.  
  43. DROP TABLE IF EXISTS portfolio_bond;
  44. CREATE TABLE IF NOT EXISTS portfolio_bond (
  45. portfolio_tuid text not null,
  46. bond_tuid text not null,
  47. amount double precision not null,
  48. aux_data jsonb not null default '{}'::jsonb,
  49. PRIMARY KEY (bond_tuid, portfolio_tuid)
  50. );
  51. `)
  52. console.log(`done`)
  53. process.exit()
  54. }
  55.  
  56. prepare()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement