From e03ae63acfb1c0e1de42ea980ece29206a2bbf99 Mon Sep 17 00:00:00 2001 From: Artur Beljajev Date: Sun, 16 Sep 2018 16:53:02 +0300 Subject: [PATCH 1/3] Remove PaperTrail columns from `prices` DB table PaperTrail's `Version` model itself has been removed in #475, so those columns are now useless --- ...20180916133911_remove_paper_trail_columns_from_prices.rb | 6 ++++++ db/structure.sql | 4 ++-- 2 files changed, 8 insertions(+), 2 deletions(-) create mode 100644 db/migrate/20180916133911_remove_paper_trail_columns_from_prices.rb diff --git a/db/migrate/20180916133911_remove_paper_trail_columns_from_prices.rb b/db/migrate/20180916133911_remove_paper_trail_columns_from_prices.rb new file mode 100644 index 000000000..a30aa939a --- /dev/null +++ b/db/migrate/20180916133911_remove_paper_trail_columns_from_prices.rb @@ -0,0 +1,6 @@ +class RemovePaperTrailColumnsFromPrices < ActiveRecord::Migration + def change + remove_column :prices, :creator_str + remove_column :prices, :updator_str + end +end diff --git a/db/structure.sql b/db/structure.sql index 912946c60..2567cbca9 100644 --- a/db/structure.sql +++ b/db/structure.sql @@ -2092,8 +2092,6 @@ CREATE TABLE public.prices ( price_cents integer NOT NULL, valid_from timestamp without time zone, valid_to timestamp without time zone, - creator_str character varying, - updator_str character varying, created_at timestamp without time zone NOT NULL, updated_at timestamp without time zone NOT NULL, duration interval, @@ -4854,3 +4852,5 @@ INSERT INTO "schema_migrations" (version) VALUES ('20200910085157'); +INSERT INTO schema_migrations (version) VALUES ('20180916133911'); + From 86ea2319c80ef0aebf999db4dedb6449e6206213 Mon Sep 17 00:00:00 2001 From: Alex Sherman Date: Thu, 10 Sep 2020 15:55:30 +0500 Subject: [PATCH 2/3] Add versions table/model for prices --- app/models/billing/price.rb | 1 + app/models/version/billing/price_version.rb | 7 ++ ..._remove_paper_trail_columns_from_prices.rb | 6 -- ...0200910102028_create_version_for_prices.rb | 26 +++++++ db/structure.sql | 68 ++++++++++++++++--- 5 files changed, 92 insertions(+), 16 deletions(-) create mode 100644 app/models/version/billing/price_version.rb delete mode 100644 db/migrate/20180916133911_remove_paper_trail_columns_from_prices.rb create mode 100644 db/migrate/20200910102028_create_version_for_prices.rb diff --git a/app/models/billing/price.rb b/app/models/billing/price.rb index 283a6e5bc..dac458b00 100644 --- a/app/models/billing/price.rb +++ b/app/models/billing/price.rb @@ -1,6 +1,7 @@ module Billing class Price < ApplicationRecord include Concerns::Billing::Price::Expirable + include Versions belongs_to :zone, class_name: 'DNS::Zone', required: true has_many :account_activities diff --git a/app/models/version/billing/price_version.rb b/app/models/version/billing/price_version.rb new file mode 100644 index 000000000..7502c18e2 --- /dev/null +++ b/app/models/version/billing/price_version.rb @@ -0,0 +1,7 @@ +module Billing + class PriceVersion < PaperTrail::Version + self.table_name = :log_prices + self.sequence_name = :log_prices_id_seq + end +end + diff --git a/db/migrate/20180916133911_remove_paper_trail_columns_from_prices.rb b/db/migrate/20180916133911_remove_paper_trail_columns_from_prices.rb deleted file mode 100644 index a30aa939a..000000000 --- a/db/migrate/20180916133911_remove_paper_trail_columns_from_prices.rb +++ /dev/null @@ -1,6 +0,0 @@ -class RemovePaperTrailColumnsFromPrices < ActiveRecord::Migration - def change - remove_column :prices, :creator_str - remove_column :prices, :updator_str - end -end diff --git a/db/migrate/20200910102028_create_version_for_prices.rb b/db/migrate/20200910102028_create_version_for_prices.rb new file mode 100644 index 000000000..85eea737f --- /dev/null +++ b/db/migrate/20200910102028_create_version_for_prices.rb @@ -0,0 +1,26 @@ +class CreateVersionForPrices < ActiveRecord::Migration[6.0] + def up + create_table :log_prices, force: :cascade do |t| + t.string :item_type, null: false + t.integer :item_id, null: false + t.string :event, null: false + t.string :whodunnit + t.json :object + t.json :object_changes + t.datetime :created_at + t.string :session + t.json :children + t.string :uuid + end + + add_index 'log_prices', ['item_type', 'item_id'], name: 'index_log_prices_on_item_type_and_item_id', using: :btree + add_index 'log_prices', ['whodunnit'], name: 'index_log_prices_on_whodunnit', using: :btree + end + + def down + remove_index :log_prices, name: 'index_log_prices_on_item_type_and_item_id' + remove_index :log_prices, name: 'index_log_prices_on_whodunnit' + + drop_table :log_prices + end +end diff --git a/db/structure.sql b/db/structure.sql index 2567cbca9..73d5f9436 100644 --- a/db/structure.sql +++ b/db/structure.sql @@ -371,6 +371,7 @@ CREATE TABLE public.bank_statements ( id integer NOT NULL, bank_code character varying, iban character varying, + import_file_path character varying, queried_at timestamp without time zone, created_at timestamp without time zone, updated_at timestamp without time zone, @@ -777,6 +778,7 @@ CREATE TABLE public.domains ( id integer NOT NULL, name character varying NOT NULL, registrar_id integer NOT NULL, + registered_at timestamp without time zone, valid_to timestamp without time zone NOT NULL, registrant_id integer NOT NULL, transfer_code character varying NOT NULL, @@ -1706,7 +1708,45 @@ ALTER SEQUENCE public.log_payment_orders_id_seq OWNED BY public.log_payment_orde -- --- Name: log_registrant_verifications; Type: TABLE; Schema: public; Owner: -; Tablespace: +-- Name: log_prices; Type: TABLE; Schema: public; Owner: - +-- + +CREATE TABLE public.log_prices ( + id bigint NOT NULL, + item_type character varying NOT NULL, + item_id integer NOT NULL, + event character varying NOT NULL, + whodunnit character varying, + object json, + object_changes json, + created_at timestamp without time zone, + session character varying, + children json, + uuid character varying +); + + +-- +-- Name: log_prices_id_seq; Type: SEQUENCE; Schema: public; Owner: - +-- + +CREATE SEQUENCE public.log_prices_id_seq + START WITH 1 + INCREMENT BY 1 + NO MINVALUE + NO MAXVALUE + CACHE 1; + + +-- +-- Name: log_prices_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: - +-- + +ALTER SEQUENCE public.log_prices_id_seq OWNED BY public.log_prices.id; + + +-- +-- Name: log_registrant_verifications; Type: TABLE; Schema: public; Owner: - -- CREATE TABLE public.log_registrant_verifications ( @@ -2084,7 +2124,7 @@ ALTER SEQUENCE public.payment_orders_id_seq OWNED BY public.payment_orders.id; -- --- Name: prices; Type: TABLE; Schema: public; Owner: -; Tablespace: +-- Name: prices; Type: TABLE; Schema: public; Owner: - -- CREATE TABLE public.prices ( @@ -2096,7 +2136,9 @@ CREATE TABLE public.prices ( updated_at timestamp without time zone NOT NULL, duration interval, operation_category character varying, - zone_id integer NOT NULL + zone_id integer NOT NULL, + updator_str character varying, + creator_str character varying ); @@ -3302,7 +3344,15 @@ ALTER TABLE ONLY public.log_payment_orders -- --- Name: log_registrant_verifications_pkey; Type: CONSTRAINT; Schema: public; Owner: -; Tablespace: +-- Name: log_prices log_prices_pkey; Type: CONSTRAINT; Schema: public; Owner: - +-- + +ALTER TABLE ONLY public.log_prices + ADD CONSTRAINT log_prices_pkey PRIMARY KEY (id); + + +-- +-- Name: log_registrant_verifications log_registrant_verifications_pkey; Type: CONSTRAINT; Schema: public; Owner: - -- ALTER TABLE ONLY public.log_registrant_verifications @@ -3310,7 +3360,7 @@ ALTER TABLE ONLY public.log_registrant_verifications -- --- Name: log_registrars_pkey; Type: CONSTRAINT; Schema: public; Owner: -; Tablespace: +-- Name: log_registrars log_registrars_pkey; Type: CONSTRAINT; Schema: public; Owner: - -- ALTER TABLE ONLY public.log_registrars @@ -4751,6 +4801,7 @@ INSERT INTO "schema_migrations" (version) VALUES ('20180825193437'), ('20180825232819'), ('20180826162821'), +('20180916133911'), ('20181001090536'), ('20181002090319'), ('20181017092829'), @@ -4824,7 +4875,6 @@ INSERT INTO "schema_migrations" (version) VALUES ('20191203083643'), ('20191206183853'), ('20191212133136'), -('20191217013225'), ('20191219112434'), ('20191219124429'), ('20191227110904'), @@ -4849,8 +4899,6 @@ INSERT INTO "schema_migrations" (version) VALUES ('20200812090409'), ('20200812125810'), ('20200908131554'), -('20200910085157'); - - -INSERT INTO schema_migrations (version) VALUES ('20180916133911'); +('20200910085157'), +('20200910102028'); From 6d908f6969892b90cf08dd51b4ec200652156313 Mon Sep 17 00:00:00 2001 From: Alex Sherman Date: Thu, 10 Sep 2020 16:21:42 +0500 Subject: [PATCH 3/3] Revert "Remove PaperTrail columns from `prices` DB table" This reverts commit 5aa949847ad391f72d6df5bf714573012a7d9cec. --- db/structure.sql | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/db/structure.sql b/db/structure.sql index 73d5f9436..15958ec0a 100644 --- a/db/structure.sql +++ b/db/structure.sql @@ -371,7 +371,6 @@ CREATE TABLE public.bank_statements ( id integer NOT NULL, bank_code character varying, iban character varying, - import_file_path character varying, queried_at timestamp without time zone, created_at timestamp without time zone, updated_at timestamp without time zone, @@ -778,7 +777,6 @@ CREATE TABLE public.domains ( id integer NOT NULL, name character varying NOT NULL, registrar_id integer NOT NULL, - registered_at timestamp without time zone, valid_to timestamp without time zone NOT NULL, registrant_id integer NOT NULL, transfer_code character varying NOT NULL, @@ -2124,7 +2122,7 @@ ALTER SEQUENCE public.payment_orders_id_seq OWNED BY public.payment_orders.id; -- --- Name: prices; Type: TABLE; Schema: public; Owner: - +-- Name: prices; Type: TABLE; Schema: public; Owner: -; Tablespace: -- CREATE TABLE public.prices ( @@ -2132,13 +2130,13 @@ CREATE TABLE public.prices ( price_cents integer NOT NULL, valid_from timestamp without time zone, valid_to timestamp without time zone, + updator_str character varying, + creator_str character varying, created_at timestamp without time zone NOT NULL, updated_at timestamp without time zone NOT NULL, duration interval, operation_category character varying, - zone_id integer NOT NULL, - updator_str character varying, - creator_str character varying + zone_id integer NOT NULL ); @@ -2878,7 +2876,14 @@ ALTER TABLE ONLY public.log_payment_orders ALTER COLUMN id SET DEFAULT nextval(' -- --- Name: id; Type: DEFAULT; Schema: public; Owner: - +-- Name: log_prices id; Type: DEFAULT; Schema: public; Owner: - +-- + +ALTER TABLE ONLY public.log_prices ALTER COLUMN id SET DEFAULT nextval('public.log_prices_id_seq'::regclass); + + +-- +-- Name: log_registrant_verifications id; Type: DEFAULT; Schema: public; Owner: - -- ALTER TABLE ONLY public.log_registrant_verifications ALTER COLUMN id SET DEFAULT nextval('public.log_registrant_verifications_id_seq'::regclass); @@ -3360,7 +3365,7 @@ ALTER TABLE ONLY public.log_registrant_verifications -- --- Name: log_registrars log_registrars_pkey; Type: CONSTRAINT; Schema: public; Owner: - +-- Name: log_registrars_pkey; Type: CONSTRAINT; Schema: public; Owner: -; Tablespace: -- ALTER TABLE ONLY public.log_registrars @@ -4801,7 +4806,6 @@ INSERT INTO "schema_migrations" (version) VALUES ('20180825193437'), ('20180825232819'), ('20180826162821'), -('20180916133911'), ('20181001090536'), ('20181002090319'), ('20181017092829'), @@ -4875,6 +4879,7 @@ INSERT INTO "schema_migrations" (version) VALUES ('20191203083643'), ('20191206183853'), ('20191212133136'), +('20191217013225'), ('20191219112434'), ('20191219124429'), ('20191227110904'),