From e8adc9c0abd1ad52a72d230ed6d2385254ffa0a8 Mon Sep 17 00:00:00 2001 From: Luke Edwards Date: Thu, 25 Apr 2019 18:07:59 -0700 Subject: [PATCH] chore: add users migration --- site/.env.example | 2 ++ site/migrations/000-create-users.js | 23 +++++++++++++++++++++++ site/package.json | 2 ++ 3 files changed, 27 insertions(+) create mode 100644 site/migrations/000-create-users.js diff --git a/site/.env.example b/site/.env.example index c2980203f1..b587a81f72 100644 --- a/site/.env.example +++ b/site/.env.example @@ -1,6 +1,8 @@ NODE_ENV= +PORT= BASEURL= +DATABASE_URL= GITHUB_CLIENT_ID= GITHUB_CLIENT_SECRET= MAPBOX_ACCESS_TOKEN= diff --git a/site/migrations/000-create-users.js b/site/migrations/000-create-users.js new file mode 100644 index 0000000000..c528c66680 --- /dev/null +++ b/site/migrations/000-create-users.js @@ -0,0 +1,23 @@ +exports.up = DB => { + DB.sql(` + create table if not exists users ( + id serial primary key, + uid character varying(255) not null unique, + name character varying(255), + username character varying(255) not null, + avatar text, + token character varying(255) not null + ); + + create unique index if not exists users_pkey ON users(id int4_ops); + create unique index if not exists users_uid_key ON users(uid text_ops); + `); +}; + +exports.down = DB => { + DB.sql(` + drop table if exists users cascade; + drop index if exists users_uid_key; + drop index if exists users_pkey; + `); +}; diff --git a/site/package.json b/site/package.json index 46ef9d03a9..32dfe6ce70 100644 --- a/site/package.json +++ b/site/package.json @@ -4,6 +4,7 @@ "description": "Docs and examples for Svelte", "scripts": { "dev": "sapper dev", + "migrate": "node-pg-migrate -r dotenv/config", "sapper": "sapper build --legacy && npm run update_shimport", "update_shimport": "cp node_modules/shimport/index.js __sapper__/build/client/shimport@0.0.14.js", "update": "node scripts/update_template.js && node scripts/get-contributors.js", @@ -38,6 +39,7 @@ "esm": "^3.2.22", "jimp": "^0.6.0", "mocha": "^6.1.3", + "node-pg-migrate": "^3.18.1", "npm-run-all": "^4.1.5", "rollup": "^1.2.2", "rollup-plugin-babel": "^4.3.2",