From fa1687baf0c27b1dc9b99af6a59b234cb8c5f4a0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Karl=20Erik=20=C3=95unapuu?= Date: Mon, 3 Feb 2020 16:47:04 +0200 Subject: [PATCH] Add PaperTrail history to PaymentOrders --- app/models/payment_order.rb | 2 +- app/models/version/payment_order_version.rb | 4 ++ .../20200130092113_create_payment_orders.rb | 2 + ...203143458_create_payment_order_versions.rb | 16 +++++ db/structure.sql | 58 ++++++++++++++++++- 5 files changed, 80 insertions(+), 2 deletions(-) create mode 100644 app/models/version/payment_order_version.rb create mode 100644 db/migrate/20200203143458_create_payment_order_versions.rb diff --git a/app/models/payment_order.rb b/app/models/payment_order.rb index e204ec5dc..5449262ba 100644 --- a/app/models/payment_order.rb +++ b/app/models/payment_order.rb @@ -1,5 +1,5 @@ class PaymentOrder < ApplicationRecord - #include Versions + include Versions include ActionView::Helpers::NumberHelper PAYMENT_INTERMEDIARIES = ENV['payments_intermediaries'].to_s.strip.split(', ').freeze diff --git a/app/models/version/payment_order_version.rb b/app/models/version/payment_order_version.rb new file mode 100644 index 000000000..e556f1021 --- /dev/null +++ b/app/models/version/payment_order_version.rb @@ -0,0 +1,4 @@ +class PaymentOrderVersion < PaperTrail::Version + self.table_name = :log_payment_orders + self.sequence_name = :log_payment_orders_id_seq +end diff --git a/db/migrate/20200130092113_create_payment_orders.rb b/db/migrate/20200130092113_create_payment_orders.rb index d3320ee9b..97d86a034 100644 --- a/db/migrate/20200130092113_create_payment_orders.rb +++ b/db/migrate/20200130092113_create_payment_orders.rb @@ -6,6 +6,8 @@ class CreatePaymentOrders < ActiveRecord::Migration[5.0] t.belongs_to :invoice, foreign_key: true t.jsonb :response, null: true t.string :notes, null: true + t.string :creator_str + t.string :updator_str t.timestamps end diff --git a/db/migrate/20200203143458_create_payment_order_versions.rb b/db/migrate/20200203143458_create_payment_order_versions.rb new file mode 100644 index 000000000..d02b300e1 --- /dev/null +++ b/db/migrate/20200203143458_create_payment_order_versions.rb @@ -0,0 +1,16 @@ +class CreatePaymentOrderVersions < ActiveRecord::Migration[5.0] + def change + create_table :log_payment_orders do |t| + t.string :item_type, null: false + t.integer :item_id, null: false + t.string :event, null: false + t.string :whodunnit + t.jsonb :object + t.jsonb :object_changes + t.datetime :created_at + t.string :session + t.jsonb :children + t.string :uuid + end + end +end diff --git a/db/structure.sql b/db/structure.sql index edf53fe6f..d694da536 100644 --- a/db/structure.sql +++ b/db/structure.sql @@ -1514,6 +1514,44 @@ CREATE SEQUENCE public.log_notifications_id_seq ALTER SEQUENCE public.log_notifications_id_seq OWNED BY public.log_notifications.id; +-- +-- Name: log_payment_orders; Type: TABLE; Schema: public; Owner: -; Tablespace: +-- + +CREATE TABLE public.log_payment_orders ( + id integer NOT NULL, + item_type character varying NOT NULL, + item_id integer NOT NULL, + event character varying NOT NULL, + whodunnit character varying, + object jsonb, + object_changes jsonb, + created_at timestamp without time zone, + session character varying, + children jsonb, + uuid character varying +); + + +-- +-- Name: log_payment_orders_id_seq; Type: SEQUENCE; Schema: public; Owner: - +-- + +CREATE SEQUENCE public.log_payment_orders_id_seq + START WITH 1 + INCREMENT BY 1 + NO MINVALUE + NO MAXVALUE + CACHE 1; + + +-- +-- Name: log_payment_orders_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: - +-- + +ALTER SEQUENCE public.log_payment_orders_id_seq OWNED BY public.log_payment_orders.id; + + -- -- Name: log_registrant_verifications; Type: TABLE; Schema: public; Owner: -; Tablespace: -- @@ -1828,6 +1866,8 @@ CREATE TABLE public.payment_orders ( invoice_id integer, response jsonb, notes character varying, + creator_str character varying, + updator_str character varying, created_at timestamp without time zone NOT NULL, updated_at timestamp without time zone NOT NULL ); @@ -2533,6 +2573,13 @@ ALTER TABLE ONLY public.log_nameservers ALTER COLUMN id SET DEFAULT nextval('pub ALTER TABLE ONLY public.log_notifications ALTER COLUMN id SET DEFAULT nextval('public.log_notifications_id_seq'::regclass); +-- +-- Name: id; Type: DEFAULT; Schema: public; Owner: - +-- + +ALTER TABLE ONLY public.log_payment_orders ALTER COLUMN id SET DEFAULT nextval('public.log_payment_orders_id_seq'::regclass); + + -- -- Name: id; Type: DEFAULT; Schema: public; Owner: - -- @@ -2945,6 +2992,14 @@ ALTER TABLE ONLY public.log_notifications ADD CONSTRAINT log_notifications_pkey PRIMARY KEY (id); +-- +-- Name: log_payment_orders_pkey; Type: CONSTRAINT; Schema: public; Owner: -; Tablespace: +-- + +ALTER TABLE ONLY public.log_payment_orders + ADD CONSTRAINT log_payment_orders_pkey PRIMARY KEY (id); + + -- -- Name: log_registrant_verifications_pkey; Type: CONSTRAINT; Schema: public; Owner: -; Tablespace: -- @@ -4404,6 +4459,7 @@ INSERT INTO "schema_migrations" (version) VALUES ('20191227110904'), ('20200113091254'), ('20200115102202'), -('20200130092113'); +('20200130092113'), +('20200203143458');