From eb68ae54b8eecd681197cbed59dfdbbf8a5501fe Mon Sep 17 00:00:00 2001 From: Copple <10214025+kiwicopple@users.noreply.github.com> Date: Thu, 30 Dec 2021 16:04:15 +0100 Subject: [PATCH 1/3] feat: self-managed migrations --- README.md | 2 +- db/migrations/0000_initial_migration.sql | 1 + ...8143846_products.sql => 0001_products.sql} | 8 +--- ...22427_customers.sql => 0002_customers.sql} | 12 +----- ...10429132018_prices.sql => 0003_prices.sql} | 22 +++++----- ...bscriptions.sql => 0004_subscriptions.sql} | 25 ++++++++---- ...1054139_invoices.sql => 0005_invoices.sql} | 19 +++++---- ...501054140_charges.sql => 0006_charges.sql} | 7 +--- ...501054141_coupons.sql => 0007_coupons.sql} | 8 +--- ...1054142_disputes.sql => 0008_disputes.sql} | 9 +---- ...10501054144_events.sql => 0009_events.sql} | 10 +---- ...501054145_payouts.sql => 0010_payouts.sql} | 10 +---- ...0210501054146_plans.sql => 0011_plans.sql} | 10 +---- db/migrations/20210428143758_init_schema.sql | 8 ---- package-lock.json | 14 +++++++ package.json | 1 + src/server.ts | 27 +++++++++---- src/utils/migrate.ts | 40 +++++++++++++++++++ 18 files changed, 122 insertions(+), 111 deletions(-) create mode 100644 db/migrations/0000_initial_migration.sql rename db/migrations/{20210428143846_products.sql => 0001_products.sql} (76%) rename db/migrations/{20210429122427_customers.sql => 0002_customers.sql} (81%) rename db/migrations/{20210429132018_prices.sql => 0003_prices.sql} (50%) rename db/migrations/{20210429140401_subscriptions.sql => 0004_subscriptions.sql} (71%) rename db/migrations/{20210501054139_invoices.sql => 0005_invoices.sql} (87%) rename db/migrations/{20210501054140_charges.sql => 0006_charges.sql} (90%) rename db/migrations/{20210501054141_coupons.sql => 0007_coupons.sql} (81%) rename db/migrations/{20210501054142_disputes.sql => 0008_disputes.sql} (77%) rename db/migrations/{20210501054144_events.sql => 0009_events.sql} (69%) rename db/migrations/{20210501054145_payouts.sql => 0010_payouts.sql} (87%) rename db/migrations/{20210501054146_plans.sql => 0011_plans.sql} (84%) delete mode 100644 db/migrations/20210428143758_init_schema.sql create mode 100644 src/utils/migrate.ts diff --git a/README.md b/README.md index 4a3fdca..222876c 100644 --- a/README.md +++ b/README.md @@ -81,9 +81,9 @@ This server synchronizes your Stripe account to a Postgres database. It can be a - Update your Stripe account with all valid webhooks and get the webhook secret - `mv .env.sample .env` and then rename all the variables - Make sure the database URL has search_path `stripe`. eg: `DATABASE_URL=postgres://postgres:postgres@hostname:5432/postgres?sslmode=disable&search_path=stripe` -- Run `dbmate up` - Deploy the [docker image](https://hub.docker.com/r/supabase/stripe-sync-engine) to your favourite hosting service and expose port `8080` - eg: `docker run -e PORT=8080 --env-file .env supabase/stripe-sync-engine` + - This will automatically run any migrations on your database - Point your Stripe webooks to your deployed app. ## Future ideas diff --git a/db/migrations/0000_initial_migration.sql b/db/migrations/0000_initial_migration.sql new file mode 100644 index 0000000..9e13a3e --- /dev/null +++ b/db/migrations/0000_initial_migration.sql @@ -0,0 +1 @@ +select 1; \ No newline at end of file diff --git a/db/migrations/20210428143846_products.sql b/db/migrations/0001_products.sql similarity index 76% rename from db/migrations/20210428143846_products.sql rename to db/migrations/0001_products.sql index 2db8548..49ee08a 100644 --- a/db/migrations/20210428143846_products.sql +++ b/db/migrations/0001_products.sql @@ -1,6 +1,4 @@ --- migrate:up - -create table "stripe"."products" ( +create table if not exists "stripe"."products" ( "id" text primary key, "object" text, "active" boolean, @@ -17,7 +15,3 @@ create table "stripe"."products" ( "updated" integer, "url" text ); - --- migrate:down - -drop table "stripe"."products"; \ No newline at end of file diff --git a/db/migrations/20210429122427_customers.sql b/db/migrations/0002_customers.sql similarity index 81% rename from db/migrations/20210429122427_customers.sql rename to db/migrations/0002_customers.sql index bddb40f..c8132f0 100644 --- a/db/migrations/20210429122427_customers.sql +++ b/db/migrations/0002_customers.sql @@ -1,7 +1,4 @@ --- migrate:up - - -create table "stripe"."customers" ( +create table if not exists "stripe"."customers" ( "id" text primary key, "object" text, "address" jsonb, @@ -24,10 +21,3 @@ create table "stripe"."customers" ( "preferred_locales" jsonb, "tax_exempt" text ); - - - --- migrate:down - - -drop table "stripe"."customers"; \ No newline at end of file diff --git a/db/migrations/20210429132018_prices.sql b/db/migrations/0003_prices.sql similarity index 50% rename from db/migrations/20210429132018_prices.sql rename to db/migrations/0003_prices.sql index 8ed2dab..e133637 100644 --- a/db/migrations/20210429132018_prices.sql +++ b/db/migrations/0003_prices.sql @@ -1,9 +1,17 @@ --- migrate:up +DO $$ +BEGIN + IF NOT EXISTS (SELECT 1 FROM pg_type WHERE typname = 'pricing_type') THEN + create type "stripe"."pricing_type" as enum ('one_time', 'recurring'); + END IF; + IF NOT EXISTS (SELECT 1 FROM pg_type WHERE typname = 'pricing_tiers') THEN + create type "stripe"."pricing_tiers" as enum ('graduated', 'volume'); + END IF; + --more types here... +END +$$; -create type "stripe"."pricing_type" as enum ('one_time', 'recurring'); -create type "stripe"."pricing_tiers" as enum ('graduated', 'volume'); -create table "stripe"."prices" ( +create table if not exists "stripe"."prices" ( "id" text primary key, "object" text, "active" boolean, @@ -24,9 +32,3 @@ create table "stripe"."prices" ( "product" text references stripe.products ); --- migrate:down - -drop table "stripe"."prices"; -drop type "stripe"."pricing_type"; -drop type "stripe"."pricing_tiers"; - diff --git a/db/migrations/20210429140401_subscriptions.sql b/db/migrations/0004_subscriptions.sql similarity index 71% rename from db/migrations/20210429140401_subscriptions.sql rename to db/migrations/0004_subscriptions.sql index ce6fa51..bd9e575 100644 --- a/db/migrations/20210429140401_subscriptions.sql +++ b/db/migrations/0004_subscriptions.sql @@ -1,7 +1,21 @@ --- migrate:up -create type "stripe"."subscription_status" as enum ('trialing', 'active', 'canceled', 'incomplete', 'incomplete_expired', 'past_due', 'unpaid'); -create table "stripe"."subscriptions" ( +DO $$ +BEGIN + IF NOT EXISTS (SELECT 1 FROM pg_type WHERE typname = 'subscription_status') THEN + create type "stripe"."subscription_status" as enum ( + 'trialing', + 'active', + 'canceled', + 'incomplete', + 'incomplete_expired', + 'past_due', + 'unpaid' + ); + END IF; +END +$$; + +create table if not exists "stripe"."subscriptions" ( "id" text primary key, "object" text, "cancel_at_period_end" boolean, @@ -40,8 +54,3 @@ create table "stripe"."subscriptions" ( "plan" text -- not yet joined ); - --- migrate:down - -drop table "stripe"."subscriptions"; -drop type "stripe"."subscription_status"; \ No newline at end of file diff --git a/db/migrations/20210501054139_invoices.sql b/db/migrations/0005_invoices.sql similarity index 87% rename from db/migrations/20210501054139_invoices.sql rename to db/migrations/0005_invoices.sql index 993c41b..0b664ed 100644 --- a/db/migrations/20210501054139_invoices.sql +++ b/db/migrations/0005_invoices.sql @@ -1,8 +1,14 @@ --- migrate:up +DO $$ +BEGIN + IF NOT EXISTS (SELECT 1 FROM pg_type WHERE typname = 'invoice_status') THEN + create type "stripe"."invoice_status" as enum ('draft', 'open', 'paid', 'uncollectible', 'void'); + END IF; +END +$$; -create type "stripe"."invoice_status" as enum ('draft', 'open', 'paid', 'uncollectible', 'void'); -create table "stripe"."invoices" ( + +create table if not exists "stripe"."invoices" ( "id" text primary key, "object" text, "auto_advance" boolean, @@ -69,10 +75,3 @@ create table "stripe"."invoices" ( "on_behalf_of" text, -- not yet implemented "charge" text -- not yet implemented ); - - - --- migrate:down - -drop table "stripe"."invoices"; -drop type "stripe"."invoice_status"; \ No newline at end of file diff --git a/db/migrations/20210501054140_charges.sql b/db/migrations/0006_charges.sql similarity index 90% rename from db/migrations/20210501054140_charges.sql rename to db/migrations/0006_charges.sql index b30f749..c364a6c 100644 --- a/db/migrations/20210501054140_charges.sql +++ b/db/migrations/0006_charges.sql @@ -1,6 +1,5 @@ --- migrate:up -CREATE TABLE stripe.charges ( +create table if not exists "stripe".charges ( id text primary key, object text, card jsonb, @@ -42,7 +41,3 @@ CREATE TABLE stripe.charges ( statement_description text, payment_method_details jsonb ); - --- migrate:down - -drop table "stripe"."charges"; \ No newline at end of file diff --git a/db/migrations/20210501054141_coupons.sql b/db/migrations/0007_coupons.sql similarity index 81% rename from db/migrations/20210501054141_coupons.sql rename to db/migrations/0007_coupons.sql index 6c26cd6..78a90d3 100644 --- a/db/migrations/20210501054141_coupons.sql +++ b/db/migrations/0007_coupons.sql @@ -1,6 +1,4 @@ --- migrate:up - -CREATE TABLE stripe.coupons ( +create table if not exists "stripe".coupons ( id text primary key, object text, name text, @@ -19,7 +17,3 @@ CREATE TABLE stripe.coupons ( duration_in_months bigint, percent_off_precise double precision ); - --- migrate:down - -drop table "stripe"."coupons"; \ No newline at end of file diff --git a/db/migrations/20210501054142_disputes.sql b/db/migrations/0008_disputes.sql similarity index 77% rename from db/migrations/20210501054142_disputes.sql rename to db/migrations/0008_disputes.sql index e6baf94..6d2e38e 100644 --- a/db/migrations/20210501054142_disputes.sql +++ b/db/migrations/0008_disputes.sql @@ -1,6 +1,4 @@ --- migrate:up - -CREATE TABLE stripe.disputes ( +create table if not exists "stripe".disputes ( id text primary key, object text, amount bigint, @@ -17,8 +15,3 @@ CREATE TABLE stripe.disputes ( balance_transactions jsonb, is_charge_refundable boolean ); - - --- migrate:down - -drop table "stripe"."disputes"; \ No newline at end of file diff --git a/db/migrations/20210501054144_events.sql b/db/migrations/0009_events.sql similarity index 69% rename from db/migrations/20210501054144_events.sql rename to db/migrations/0009_events.sql index f05323d..bdc984f 100644 --- a/db/migrations/20210501054144_events.sql +++ b/db/migrations/0009_events.sql @@ -1,7 +1,4 @@ --- migrate:up - - -CREATE TABLE stripe.events ( +create table if not exists "stripe".events ( id text primary key, object text, data jsonb, @@ -13,8 +10,3 @@ CREATE TABLE stripe.events ( api_version text, pending_webhooks bigint ); - - --- migrate:down - -drop table "stripe"."events"; \ No newline at end of file diff --git a/db/migrations/20210501054145_payouts.sql b/db/migrations/0010_payouts.sql similarity index 87% rename from db/migrations/20210501054145_payouts.sql rename to db/migrations/0010_payouts.sql index 4a28156..6bf4e59 100644 --- a/db/migrations/20210501054145_payouts.sql +++ b/db/migrations/0010_payouts.sql @@ -1,7 +1,4 @@ --- migrate:up - - -CREATE TABLE stripe.payouts ( +create table if not exists "stripe".payouts ( id text primary key, object text, date text, @@ -31,8 +28,3 @@ CREATE TABLE stripe.payouts ( statement_description text, failure_balance_transaction text ); - - --- migrate:down - -drop table "stripe"."payouts"; \ No newline at end of file diff --git a/db/migrations/20210501054146_plans.sql b/db/migrations/0011_plans.sql similarity index 84% rename from db/migrations/20210501054146_plans.sql rename to db/migrations/0011_plans.sql index 55d1ecf..9551c44 100644 --- a/db/migrations/20210501054146_plans.sql +++ b/db/migrations/0011_plans.sql @@ -1,7 +1,4 @@ --- migrate:up - - -CREATE TABLE "stripe"."plans" ( +create table if not exists "stripe"."plans" ( id text primary key, object text, name text, @@ -26,8 +23,3 @@ CREATE TABLE "stripe"."plans" ( statement_descriptor text, statement_description text ); - - --- migrate:down - -drop table "stripe"."plans"; \ No newline at end of file diff --git a/db/migrations/20210428143758_init_schema.sql b/db/migrations/20210428143758_init_schema.sql deleted file mode 100644 index bbbaf9d..0000000 --- a/db/migrations/20210428143758_init_schema.sql +++ /dev/null @@ -1,8 +0,0 @@ --- migrate:up - -create schema if not exists stripe; - --- migrate:down - -drop schema if exists stripe; - diff --git a/package-lock.json b/package-lock.json index 8b758fc..9844524 100644 --- a/package-lock.json +++ b/package-lock.json @@ -4910,6 +4910,15 @@ "resolved": "https://registry.npmjs.org/pg-int8/-/pg-int8-1.0.1.tgz", "integrity": "sha512-WCtabS6t3c8SkpDBUlb1kjOs7l66xsGdKpIPZsg4wR+B3+u9UAum2odSsF9tnvxg80h4ZxLWMy4pRjOsFIqQpw==" }, + "pg-node-migrations": { + "version": "0.0.7", + "resolved": "https://registry.npmjs.org/pg-node-migrations/-/pg-node-migrations-0.0.7.tgz", + "integrity": "sha512-imw6BlHt5Y0wE7uvK5HXcPFoGFymPOpDJQQHTfbxE1vIR4ScjT8r9BwU/CHjxzBtNgVjlmo9thljPXxrT8bxsw==", + "requires": { + "pg": "^8.6.0", + "sql-template-strings": "^2.2.2" + } + }, "pg-pool": { "version": "3.3.0", "resolved": "https://registry.npmjs.org/pg-pool/-/pg-pool-3.3.0.tgz", @@ -6078,6 +6087,11 @@ "integrity": "sha1-BOaSb2YolTVPPdAVIDYzuFcpfiw=", "dev": true }, + "sql-template-strings": { + "version": "2.2.2", + "resolved": "https://registry.npmjs.org/sql-template-strings/-/sql-template-strings-2.2.2.tgz", + "integrity": "sha1-PxFQiiWt384hejBCqdMAwxk7lv8=" + }, "sshpk": { "version": "1.16.1", "resolved": "https://registry.npmjs.org/sshpk/-/sshpk-1.16.1.tgz", diff --git a/package.json b/package.json index 9433b5c..db7dbaa 100644 --- a/package.json +++ b/package.json @@ -33,6 +33,7 @@ "fastify-autoload": "^3.5.2", "fastify-swagger": "^4.4.1", "pg": "^8.6.0", + "pg-node-migrations": "0.0.7", "stripe": "^8.145.0", "yesql": "^5.0.0" }, diff --git a/src/server.ts b/src/server.ts index df10176..07e6ff5 100644 --- a/src/server.ts +++ b/src/server.ts @@ -1,5 +1,6 @@ import { FastifyInstance } from 'fastify' import { Server, IncomingMessage, ServerResponse } from 'http' +import { runMigrations } from './utils/migrate' import build from './app' const loggerConfig = { @@ -15,11 +16,21 @@ const app: FastifyInstance = build({ exposeDocs, }) -const port = process.env.PORT || 8080 -app.listen(port, '0.0.0.0', (err, address) => { - if (err) { - console.error(err) - process.exit(1) - } - console.log(`Server listening at ${address}`) -}) +const main = async () => { + // Init config + const port = process.env.PORT || 8080 + + // Run migrations + await runMigrations() + + // Start the server + app.listen(port, '0.0.0.0', (err, address) => { + if (err) { + console.error(err) + process.exit(1) + } + console.log(`Server listening at ${address}`) + }) +} + +main() diff --git a/src/utils/migrate.ts b/src/utils/migrate.ts new file mode 100644 index 0000000..b2ee840 --- /dev/null +++ b/src/utils/migrate.ts @@ -0,0 +1,40 @@ +import { Client } from 'pg' +import { migrate } from 'pg-node-migrations' +import { getConfig } from './config' + +const config = getConfig() + +async function connectAndMigrate( + databaseUrl: string | undefined, + migrationsDirectory: string, + logOnError = false +) { + const dbConfig = { + connectionString: databaseUrl, + connectionTimeoutMillis: 1000, + } + const optionalConfig = { + schemaName: config.SCHEMA, + tableName: 'migrations', + } + + const client = new Client(dbConfig) + try { + await client.connect() + await migrate({ client }, migrationsDirectory, optionalConfig) + } catch (error) { + if (logOnError && error instanceof Error) { + console.error('Migration error:', error.message) + } else { + throw error + } + } finally { + await client.end() + } +} + +export async function runMigrations(): Promise { + console.log('Running migrations') + await connectAndMigrate(config.DATABASE_URL, './db/migrations') + console.log('Finished migrations') +} \ No newline at end of file From b8e3548f2ea3455b37e9ed93e5b4c2bf8eafc4e5 Mon Sep 17 00:00:00 2001 From: Copple <10214025+kiwicopple@users.noreply.github.com> Date: Thu, 30 Dec 2021 16:05:46 +0100 Subject: [PATCH 2/3] Remove all occurences of dbmate --- README.md | 1 - db/schema.sql | 602 -------------------------------------------------- package.json | 1 - 3 files changed, 604 deletions(-) delete mode 100644 db/schema.sql diff --git a/README.md b/README.md index 222876c..5615df4 100644 --- a/README.md +++ b/README.md @@ -96,7 +96,6 @@ This server synchronizes your Stripe account to a Postgres database. It can be a - Create a Postgres database on [supabase.com](https://supabase.com) (or another Postgres provider) - Update Stripe with all valid webhooks and get the webhook secret - `mv .env.sample .env` and then rename all the variables -- run `dbmate up` to run all the database migrations **Develop** diff --git a/db/schema.sql b/db/schema.sql deleted file mode 100644 index dceb253..0000000 --- a/db/schema.sql +++ /dev/null @@ -1,602 +0,0 @@ -SET statement_timeout = 0; -SET lock_timeout = 0; -SET idle_in_transaction_session_timeout = 0; -SET client_encoding = 'UTF8'; -SET standard_conforming_strings = on; -SELECT pg_catalog.set_config('search_path', '', false); -SET check_function_bodies = false; -SET xmloption = content; -SET client_min_messages = warning; -SET row_security = off; - --- --- Name: stripe; Type: SCHEMA; Schema: -; Owner: - --- - -CREATE SCHEMA stripe; - - --- --- Name: invoice_status; Type: TYPE; Schema: stripe; Owner: - --- - -CREATE TYPE stripe.invoice_status AS ENUM ( - 'draft', - 'open', - 'paid', - 'uncollectible', - 'void' -); - - --- --- Name: pricing_tiers; Type: TYPE; Schema: stripe; Owner: - --- - -CREATE TYPE stripe.pricing_tiers AS ENUM ( - 'graduated', - 'volume' -); - - --- --- Name: pricing_type; Type: TYPE; Schema: stripe; Owner: - --- - -CREATE TYPE stripe.pricing_type AS ENUM ( - 'one_time', - 'recurring' -); - - --- --- Name: subscription_status; Type: TYPE; Schema: stripe; Owner: - --- - -CREATE TYPE stripe.subscription_status AS ENUM ( - 'trialing', - 'active', - 'canceled', - 'incomplete', - 'incomplete_expired', - 'past_due', - 'unpaid' -); - - -SET default_tablespace = ''; - -SET default_table_access_method = heap; - --- --- Name: charges; Type: TABLE; Schema: stripe; Owner: - --- - -CREATE TABLE stripe.charges ( - id text NOT NULL, - object text, - card jsonb, - paid boolean, - "order" text, - amount bigint, - review text, - source jsonb, - status text, - created integer, - dispute text, - invoice text, - outcome jsonb, - refunds jsonb, - updated integer, - captured boolean, - currency text, - customer text, - livemode boolean, - metadata jsonb, - refunded boolean, - shipping jsonb, - application text, - description text, - destination text, - failure_code text, - on_behalf_of text, - fraud_details jsonb, - receipt_email text, - payment_intent text, - receipt_number text, - transfer_group text, - amount_refunded bigint, - application_fee text, - failure_message text, - source_transfer text, - balance_transaction text, - statement_descriptor text, - statement_description text, - payment_method_details jsonb -); - - --- --- Name: coupons; Type: TABLE; Schema: stripe; Owner: - --- - -CREATE TABLE stripe.coupons ( - id text NOT NULL, - object text, - name text, - valid boolean, - created integer, - updated integer, - currency text, - duration text, - livemode boolean, - metadata jsonb, - redeem_by integer, - amount_off bigint, - percent_off double precision, - times_redeemed bigint, - max_redemptions bigint, - duration_in_months bigint, - percent_off_precise double precision -); - - --- --- Name: customers; Type: TABLE; Schema: stripe; Owner: - --- - -CREATE TABLE stripe.customers ( - id text NOT NULL, - object text, - address jsonb, - description text, - email text, - metadata jsonb, - name text, - phone text, - shipping jsonb, - balance integer, - created integer, - currency text, - default_source text, - delinquent boolean, - discount jsonb, - invoice_prefix text, - invoice_settings jsonb, - livemode boolean, - next_invoice_sequence integer, - preferred_locales jsonb, - tax_exempt text -); - - --- --- Name: disputes; Type: TABLE; Schema: stripe; Owner: - --- - -CREATE TABLE stripe.disputes ( - id text NOT NULL, - object text, - amount bigint, - charge text, - reason text, - status text, - created integer, - updated integer, - currency text, - evidence jsonb, - livemode boolean, - metadata jsonb, - evidence_details jsonb, - balance_transactions jsonb, - is_charge_refundable boolean -); - - --- --- Name: events; Type: TABLE; Schema: stripe; Owner: - --- - -CREATE TABLE stripe.events ( - id text NOT NULL, - object text, - data jsonb, - type text, - created integer, - request text, - updated integer, - livemode boolean, - api_version text, - pending_webhooks bigint -); - - --- --- Name: invoices; Type: TABLE; Schema: stripe; Owner: - --- - -CREATE TABLE stripe.invoices ( - id text NOT NULL, - object text, - auto_advance boolean, - collection_method text, - currency text, - description text, - hosted_invoice_url text, - lines jsonb, - metadata jsonb, - period_end integer, - period_start integer, - status stripe.invoice_status, - total bigint, - account_country text, - account_name text, - account_tax_ids jsonb, - amount_due bigint, - amount_paid bigint, - amount_remaining bigint, - application_fee_amount bigint, - attempt_count integer, - attempted boolean, - billing_reason text, - created integer, - custom_fields jsonb, - customer_address jsonb, - customer_email text, - customer_name text, - customer_phone text, - customer_shipping jsonb, - customer_tax_exempt text, - customer_tax_ids jsonb, - default_tax_rates jsonb, - discount jsonb, - discounts jsonb, - due_date integer, - ending_balance integer, - footer text, - invoice_pdf text, - last_finalization_error jsonb, - livemode boolean, - next_payment_attempt integer, - number text, - paid boolean, - payment_settings jsonb, - post_payment_credit_notes_amount integer, - pre_payment_credit_notes_amount integer, - receipt_number text, - starting_balance integer, - statement_descriptor text, - status_transitions jsonb, - subtotal integer, - tax integer, - total_discount_amounts jsonb, - total_tax_amounts jsonb, - transfer_data jsonb, - webhooks_delivered_at integer, - customer text, - subscription text, - payment_intent text, - default_payment_method text, - default_source text, - on_behalf_of text, - charge text -); - - --- --- Name: payouts; Type: TABLE; Schema: stripe; Owner: - --- - -CREATE TABLE stripe.payouts ( - id text NOT NULL, - object text, - date text, - type text, - amount bigint, - method text, - status text, - created integer, - updated integer, - currency text, - livemode boolean, - metadata jsonb, - automatic boolean, - recipient text, - description text, - destination text, - source_type text, - arrival_date text, - bank_account jsonb, - failure_code text, - transfer_group text, - amount_reversed bigint, - failure_message text, - source_transaction text, - balance_transaction text, - statement_descriptor text, - statement_description text, - failure_balance_transaction text -); - - --- --- Name: plans; Type: TABLE; Schema: stripe; Owner: - --- - -CREATE TABLE stripe.plans ( - id text NOT NULL, - object text, - name text, - tiers jsonb, - active boolean, - amount bigint, - created integer, - product text, - updated integer, - currency text, - "interval" text, - livemode boolean, - metadata jsonb, - nickname text, - tiers_mode text, - usage_type text, - billing_scheme text, - interval_count bigint, - aggregate_usage text, - transform_usage text, - trial_period_days bigint, - statement_descriptor text, - statement_description text -); - - --- --- Name: prices; Type: TABLE; Schema: stripe; Owner: - --- - -CREATE TABLE stripe.prices ( - id text NOT NULL, - object text, - active boolean, - currency text, - metadata jsonb, - nickname text, - recurring jsonb, - type stripe.pricing_type, - unit_amount integer, - billing_scheme text, - created integer, - livemode boolean, - lookup_key text, - tiers_mode stripe.pricing_tiers, - transform_quantity jsonb, - unit_amount_decimal text, - product text -); - - --- --- Name: products; Type: TABLE; Schema: stripe; Owner: - --- - -CREATE TABLE stripe.products ( - id text NOT NULL, - object text, - active boolean, - description text, - metadata jsonb, - name text, - created integer, - images jsonb, - livemode boolean, - package_dimensions jsonb, - shippable boolean, - statement_descriptor text, - unit_label text, - updated integer, - url text -); - - --- --- Name: schema_migrations; Type: TABLE; Schema: stripe; Owner: - --- - -CREATE TABLE stripe.schema_migrations ( - version character varying(255) NOT NULL -); - - --- --- Name: subscriptions; Type: TABLE; Schema: stripe; Owner: - --- - -CREATE TABLE stripe.subscriptions ( - id text NOT NULL, - object text, - cancel_at_period_end boolean, - current_period_end integer, - current_period_start integer, - default_payment_method text, - items jsonb, - metadata jsonb, - pending_setup_intent text, - pending_update jsonb, - status stripe.subscription_status, - application_fee_percent double precision, - billing_cycle_anchor integer, - billing_thresholds jsonb, - cancel_at integer, - canceled_at integer, - collection_method text, - created integer, - days_until_due integer, - default_source text, - default_tax_rates jsonb, - discount jsonb, - ended_at integer, - livemode boolean, - next_pending_invoice_item_invoice integer, - pause_collection jsonb, - pending_invoice_item_interval jsonb, - start_date integer, - transfer_data jsonb, - trial_end jsonb, - trial_start jsonb, - schedule text, - customer text, - latest_invoice text, - plan text -); - - --- --- Name: charges charges_pkey; Type: CONSTRAINT; Schema: stripe; Owner: - --- - -ALTER TABLE ONLY stripe.charges - ADD CONSTRAINT charges_pkey PRIMARY KEY (id); - - --- --- Name: coupons coupons_pkey; Type: CONSTRAINT; Schema: stripe; Owner: - --- - -ALTER TABLE ONLY stripe.coupons - ADD CONSTRAINT coupons_pkey PRIMARY KEY (id); - - --- --- Name: customers customers_pkey; Type: CONSTRAINT; Schema: stripe; Owner: - --- - -ALTER TABLE ONLY stripe.customers - ADD CONSTRAINT customers_pkey PRIMARY KEY (id); - - --- --- Name: disputes disputes_pkey; Type: CONSTRAINT; Schema: stripe; Owner: - --- - -ALTER TABLE ONLY stripe.disputes - ADD CONSTRAINT disputes_pkey PRIMARY KEY (id); - - --- --- Name: events events_pkey; Type: CONSTRAINT; Schema: stripe; Owner: - --- - -ALTER TABLE ONLY stripe.events - ADD CONSTRAINT events_pkey PRIMARY KEY (id); - - --- --- Name: invoices invoices_pkey; Type: CONSTRAINT; Schema: stripe; Owner: - --- - -ALTER TABLE ONLY stripe.invoices - ADD CONSTRAINT invoices_pkey PRIMARY KEY (id); - - --- --- Name: payouts payouts_pkey; Type: CONSTRAINT; Schema: stripe; Owner: - --- - -ALTER TABLE ONLY stripe.payouts - ADD CONSTRAINT payouts_pkey PRIMARY KEY (id); - - --- --- Name: plans plans_pkey; Type: CONSTRAINT; Schema: stripe; Owner: - --- - -ALTER TABLE ONLY stripe.plans - ADD CONSTRAINT plans_pkey PRIMARY KEY (id); - - --- --- Name: prices prices_pkey; Type: CONSTRAINT; Schema: stripe; Owner: - --- - -ALTER TABLE ONLY stripe.prices - ADD CONSTRAINT prices_pkey PRIMARY KEY (id); - - --- --- Name: products products_pkey; Type: CONSTRAINT; Schema: stripe; Owner: - --- - -ALTER TABLE ONLY stripe.products - ADD CONSTRAINT products_pkey PRIMARY KEY (id); - - --- --- Name: schema_migrations schema_migrations_pkey; Type: CONSTRAINT; Schema: stripe; Owner: - --- - -ALTER TABLE ONLY stripe.schema_migrations - ADD CONSTRAINT schema_migrations_pkey PRIMARY KEY (version); - - --- --- Name: subscriptions subscriptions_pkey; Type: CONSTRAINT; Schema: stripe; Owner: - --- - -ALTER TABLE ONLY stripe.subscriptions - ADD CONSTRAINT subscriptions_pkey PRIMARY KEY (id); - - --- --- Name: invoices invoices_customer_fkey; Type: FK CONSTRAINT; Schema: stripe; Owner: - --- - -ALTER TABLE ONLY stripe.invoices - ADD CONSTRAINT invoices_customer_fkey FOREIGN KEY (customer) REFERENCES stripe.customers(id); - - --- --- Name: invoices invoices_subscription_fkey; Type: FK CONSTRAINT; Schema: stripe; Owner: - --- - -ALTER TABLE ONLY stripe.invoices - ADD CONSTRAINT invoices_subscription_fkey FOREIGN KEY (subscription) REFERENCES stripe.subscriptions(id); - - --- --- Name: prices prices_product_fkey; Type: FK CONSTRAINT; Schema: stripe; Owner: - --- - -ALTER TABLE ONLY stripe.prices - ADD CONSTRAINT prices_product_fkey FOREIGN KEY (product) REFERENCES stripe.products(id); - - --- --- Name: subscriptions subscriptions_customer_fkey; Type: FK CONSTRAINT; Schema: stripe; Owner: - --- - -ALTER TABLE ONLY stripe.subscriptions - ADD CONSTRAINT subscriptions_customer_fkey FOREIGN KEY (customer) REFERENCES stripe.customers(id); - - --- --- PostgreSQL database dump complete --- - - --- --- Dbmate schema migrations --- - -INSERT INTO stripe.schema_migrations (version) VALUES - ('20210428143758'), - ('20210428143846'), - ('20210429122427'), - ('20210429132018'), - ('20210429140401'), - ('20210501054139'), - ('20210501054140'), - ('20210501054141'), - ('20210501054142'), - ('20210501054144'), - ('20210501054145'), - ('20210501054146'); diff --git a/package.json b/package.json index db7dbaa..0a2c003 100644 --- a/package.json +++ b/package.json @@ -9,7 +9,6 @@ "start": "NODE_ENV=production node dist/server.js", "test": "node -r dotenv/config node_modules/.bin/jest --runInBand", "test:debug": "TERM=dumb node -r dotenv/config node_modules/.bin/jest", - "migrate:new": "dbmate new RENAME", "eslint:check": "eslint 'src/**'", "prettier:check": "prettier -c src/**", "prettier:write": "prettier --write src/**", From 55ed572e1ceca6fd6b9f046904c9a96c6011a135 Mon Sep 17 00:00:00 2001 From: Copple <10214025+kiwicopple@users.noreply.github.com> Date: Thu, 30 Dec 2021 16:06:46 +0100 Subject: [PATCH 3/3] clean code --- src/utils/migrate.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/utils/migrate.ts b/src/utils/migrate.ts index b2ee840..597ba40 100644 --- a/src/utils/migrate.ts +++ b/src/utils/migrate.ts @@ -37,4 +37,4 @@ export async function runMigrations(): Promise { console.log('Running migrations') await connectAndMigrate(config.DATABASE_URL, './db/migrations') console.log('Finished migrations') -} \ No newline at end of file +}