From 7fdaf1d79aed8dab82264dedfc3616ebc84f0b9e Mon Sep 17 00:00:00 2001 From: Artur Beljajev Date: Thu, 20 Jun 2019 11:54:50 +0300 Subject: [PATCH] Add `ActionVersion` --- app/models/action.rb | 2 + app/models/version/action_version.rb | 4 ++ .../20190620084334_create_log_actions.rb | 16 ++++++ db/structure.sql | 55 +++++++++++++++++++ 4 files changed, 77 insertions(+) create mode 100644 app/models/version/action_version.rb create mode 100644 db/migrate/20190620084334_create_log_actions.rb diff --git a/app/models/action.rb b/app/models/action.rb index 2a60f9a239..ef16c8d687 100644 --- a/app/models/action.rb +++ b/app/models/action.rb @@ -1,4 +1,6 @@ class Action < ActiveRecord::Base + has_paper_trail + belongs_to :user belongs_to :contact diff --git a/app/models/version/action_version.rb b/app/models/version/action_version.rb new file mode 100644 index 0000000000..bd23d7697e --- /dev/null +++ b/app/models/version/action_version.rb @@ -0,0 +1,4 @@ +class ActionVersion < PaperTrail::Version + self.table_name = :log_actions + self.sequence_name = :log_actions_id_seq +end diff --git a/db/migrate/20190620084334_create_log_actions.rb b/db/migrate/20190620084334_create_log_actions.rb new file mode 100644 index 0000000000..4ce7e8ab4b --- /dev/null +++ b/db/migrate/20190620084334_create_log_actions.rb @@ -0,0 +1,16 @@ +class CreateLogActions < ActiveRecord::Migration + def change + create_table :log_actions 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 83716ff1e9..d1f379a74c 100644 --- a/db/structure.sql +++ b/db/structure.sql @@ -1147,6 +1147,44 @@ CREATE SEQUENCE public.log_accounts_id_seq ALTER SEQUENCE public.log_accounts_id_seq OWNED BY public.log_accounts.id; +-- +-- Name: log_actions; Type: TABLE; Schema: public; Owner: -; Tablespace: +-- + +CREATE TABLE public.log_actions ( + 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_actions_id_seq; Type: SEQUENCE; Schema: public; Owner: - +-- + +CREATE SEQUENCE public.log_actions_id_seq + START WITH 1 + INCREMENT BY 1 + NO MINVALUE + NO MAXVALUE + CACHE 1; + + +-- +-- Name: log_actions_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: - +-- + +ALTER SEQUENCE public.log_actions_id_seq OWNED BY public.log_actions.id; + + -- -- Name: log_bank_statements; Type: TABLE; Schema: public; Owner: -; Tablespace: -- @@ -2506,6 +2544,13 @@ ALTER TABLE ONLY public.log_account_activities ALTER COLUMN id SET DEFAULT nextv ALTER TABLE ONLY public.log_accounts ALTER COLUMN id SET DEFAULT nextval('public.log_accounts_id_seq'::regclass); +-- +-- Name: id; Type: DEFAULT; Schema: public; Owner: - +-- + +ALTER TABLE ONLY public.log_actions ALTER COLUMN id SET DEFAULT nextval('public.log_actions_id_seq'::regclass); + + -- -- Name: id; Type: DEFAULT; Schema: public; Owner: - -- @@ -2891,6 +2936,14 @@ ALTER TABLE ONLY public.log_accounts ADD CONSTRAINT log_accounts_pkey PRIMARY KEY (id); +-- +-- Name: log_actions_pkey; Type: CONSTRAINT; Schema: public; Owner: -; Tablespace: +-- + +ALTER TABLE ONLY public.log_actions + ADD CONSTRAINT log_actions_pkey PRIMARY KEY (id); + + -- -- Name: log_bank_statements_pkey; Type: CONSTRAINT; Schema: public; Owner: -; Tablespace: -- @@ -4763,3 +4816,5 @@ INSERT INTO schema_migrations (version) VALUES ('20190617121949'); INSERT INTO schema_migrations (version) VALUES ('20190617122505'); +INSERT INTO schema_migrations (version) VALUES ('20190620084334'); +