-
Notifications
You must be signed in to change notification settings - Fork 38
Handle tables with custom fillfactor + add tests + add CI
#46
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| name: CI | ||
| on: | ||
| pull_request: | ||
| jobs: | ||
| test: | ||
| runs-on: ubuntu-latest | ||
| strategy: | ||
| matrix: | ||
| ruby: ["3.1", "3.2"] | ||
| steps: | ||
| - uses: actions/checkout@v3 | ||
| - uses: ruby/setup-ruby@v1 | ||
| with: | ||
| ruby-version: ${{ matrix.ruby }} | ||
| bundler-cache: true | ||
| - run: bundle exec rake test |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,12 @@ | ||
| require 'rubygems' | ||
| require 'bundler/setup' | ||
| require 'bundler/gem_tasks' | ||
| require "rake/testtask" | ||
|
|
||
| Rake::TestTask.new(:test) do |t| | ||
| t.libs << "test" | ||
| t.libs << "lib" | ||
| t.test_files = FileList["test/**/*_test.rb"] | ||
| end | ||
|
|
||
| task default: %i[test] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -84,7 +84,7 @@ def run | |
| partitioned_tables += dump.scan(partitioned_tables_regexp2).map(&:first) | ||
|
|
||
| partitioned_tables.each do |partitioned_table| | ||
| partitioned_schema_name, partitioned_table_name_only = partitioned_table.split('.', 2) | ||
| _partitioned_schema_name, partitioned_table_name_only = partitioned_table.split('.', 2) | ||
| dump.gsub!(/-- Name: #{partitioned_table_name_only}; Type: TABLE/, '') | ||
| dump.gsub!(/CREATE TABLE #{partitioned_table} \([^;]+;/m, '') | ||
| dump.gsub!(/ALTER TABLE ONLY ([\w_\.]+) ATTACH PARTITION #{partitioned_table}[^;]+;/m, '') | ||
|
|
@@ -124,7 +124,7 @@ def run | |
| dump.gsub!(/^CREATE( UNIQUE)? INDEX \w+ ON .+\n+/, '') | ||
| dump.gsub!(/^-- Name: \w+; Type: INDEX\n+/, '') | ||
| indexes.each do |table, indexes_for_table| | ||
| dump.gsub!(/^(CREATE TABLE #{table}\b(:?[^;\n]*\n)+\);\n)/) { $1 + "\n" + indexes_for_table } | ||
| dump.gsub!(/^(CREATE TABLE #{table}\b(:?[^;\n]*\n)+\);*\n(?:.*);*)/) { $1 + "\n\n" + indexes_for_table } | ||
| end | ||
| end | ||
|
|
||
|
|
@@ -151,7 +151,7 @@ def order_column_definitions(source) | |
| inside_table = true | ||
| columns = [] | ||
| result << source_line | ||
| elsif source_line.start_with?(");") | ||
| elsif source_line.start_with?(")") | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
| if inside_table | ||
| inside_table = false | ||
| columns.sort_by!(&:first) | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,35 @@ | ||
| require "test_helper" | ||
|
|
||
| class CleanDumpTest < Minitest::Test | ||
| def test_basic_case | ||
| assert_cleans_dump "expectations/default_props.sql", {} | ||
| end | ||
|
|
||
| def test_ignore_ids | ||
| assert_cleans_dump "expectations/ignore_ids.sql", { ignore_ids: true } | ||
| end | ||
|
|
||
| def test_order_column_definitions | ||
| assert_cleans_dump "expectations/order_column_definitions.sql", { order_column_definitions: true } | ||
| end | ||
|
|
||
| def test_order_schema_migrations_values | ||
| assert_cleans_dump "expectations/order_schema_migrations_values.sql", { order_schema_migrations_values: true } | ||
| end | ||
|
|
||
| def test_indexes_after_tables | ||
| assert_cleans_dump "expectations/indexes_after_tables.sql", { indexes_after_tables: true } | ||
| end | ||
|
|
||
| def test_keep_extensions_all | ||
| assert_cleans_dump "expectations/keep_extensions_all.sql", { keep_extensions: :all } | ||
| end | ||
|
|
||
| private | ||
|
|
||
| def assert_cleans_dump(expected_output_path, props) | ||
| cleaner = ActiveRecordCleanDbStructure::CleanDump.new(File.read(File.join(__dir__, "data/input.sql")), props) | ||
| cleaner.run | ||
| assert_equal File.read(File.join(__dir__, expected_output_path)), cleaner.dump | ||
| end | ||
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,162 @@ | ||
| 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: pg_stat_statements; Type: EXTENSION; Schema: -; Owner: - | ||
| -- | ||
|
|
||
| CREATE EXTENSION IF NOT EXISTS pg_stat_statements WITH SCHEMA public; | ||
|
|
||
|
|
||
| -- | ||
| -- Name: EXTENSION pg_stat_statements; Type: COMMENT; Schema: -; Owner: - | ||
| -- | ||
|
|
||
| COMMENT ON EXTENSION pg_stat_statements IS 'track execution statistics of all SQL statements executed'; | ||
|
|
||
|
|
||
| SET default_tablespace = ''; | ||
|
|
||
| SET default_table_access_method = heap; | ||
|
|
||
| -- | ||
| -- Name: ar_internal_metadata; Type: TABLE; Schema: public; Owner: - | ||
| -- | ||
|
|
||
| CREATE TABLE public.ar_internal_metadata ( | ||
| key character varying NOT NULL, | ||
| value character varying, | ||
| created_at timestamp(6) without time zone NOT NULL, | ||
| updated_at timestamp(6) without time zone NOT NULL | ||
| ); | ||
|
|
||
|
|
||
| -- | ||
| -- Name: delayed_jobs; Type: TABLE; Schema: public; Owner: - | ||
| -- | ||
|
|
||
| CREATE TABLE public.delayed_jobs ( | ||
| id bigint NOT NULL, | ||
| priority integer DEFAULT 0, | ||
| attempts integer DEFAULT 0, | ||
| handler text, | ||
| last_error text, | ||
| run_at timestamp without time zone, | ||
| locked_at timestamp without time zone, | ||
| failed_at timestamp without time zone, | ||
| locked_by character varying(255), | ||
| queue character varying(255), | ||
| created_at timestamp without time zone NOT NULL, | ||
| updated_at timestamp without time zone NOT NULL, | ||
| metadata jsonb DEFAULT '{}'::jsonb, | ||
| whodunnit text | ||
| ) | ||
| WITH (fillfactor='85'); | ||
|
|
||
|
|
||
| -- | ||
| -- Name: delayed_jobs_id_seq; Type: SEQUENCE; Schema: public; Owner: - | ||
| -- | ||
|
|
||
| CREATE SEQUENCE public.delayed_jobs_id_seq | ||
| START WITH 1 | ||
| INCREMENT BY 1 | ||
| NO MINVALUE | ||
| NO MAXVALUE | ||
| CACHE 1; | ||
|
|
||
|
|
||
| -- | ||
| -- Name: delayed_jobs_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: - | ||
| -- | ||
|
|
||
| ALTER SEQUENCE public.delayed_jobs_id_seq OWNED BY public.delayed_jobs.id; | ||
|
|
||
|
|
||
| -- | ||
| -- Name: schema_migrations; Type: TABLE; Schema: public; Owner: - | ||
| -- | ||
|
|
||
| CREATE TABLE public.schema_migrations ( | ||
| version character varying NOT NULL | ||
| ); | ||
|
|
||
|
|
||
| -- | ||
| -- Name: delayed_jobs id; Type: DEFAULT; Schema: public; Owner: - | ||
| -- | ||
|
|
||
| ALTER TABLE ONLY public.delayed_jobs ALTER COLUMN id SET DEFAULT nextval('public.delayed_jobs_id_seq'::regclass); | ||
|
|
||
|
|
||
| -- | ||
| -- Name: ar_internal_metadata ar_internal_metadata_pkey; Type: CONSTRAINT; Schema: public; Owner: - | ||
| -- | ||
|
|
||
| ALTER TABLE ONLY public.ar_internal_metadata | ||
| ADD CONSTRAINT ar_internal_metadata_pkey PRIMARY KEY (key); | ||
|
|
||
|
|
||
| -- | ||
| -- Name: delayed_jobs delayed_jobs_pkey; Type: CONSTRAINT; Schema: public; Owner: - | ||
| -- | ||
|
|
||
| ALTER TABLE ONLY public.delayed_jobs | ||
| ADD CONSTRAINT delayed_jobs_pkey PRIMARY KEY (id); | ||
|
|
||
|
|
||
| -- | ||
| -- Name: schema_migrations schema_migrations_pkey; Type: CONSTRAINT; Schema: public; Owner: - | ||
| -- | ||
|
|
||
| ALTER TABLE ONLY public.schema_migrations | ||
| ADD CONSTRAINT schema_migrations_pkey PRIMARY KEY (version); | ||
|
|
||
|
|
||
| -- | ||
| -- Name: index_delayed_jobs_on_locked_by; Type: INDEX; Schema: public; Owner: - | ||
| -- | ||
|
|
||
| CREATE INDEX index_delayed_jobs_on_locked_by ON public.delayed_jobs USING btree (locked_by); | ||
|
|
||
|
|
||
| -- | ||
| -- Name: index_delayed_jobs_on_queue; Type: INDEX; Schema: public; Owner: - | ||
| -- | ||
|
|
||
| CREATE INDEX index_delayed_jobs_on_queue ON public.delayed_jobs USING btree (queue); | ||
|
|
||
|
|
||
| -- | ||
| -- Name: index_delayed_jobs_on_run_at; Type: INDEX; Schema: public; Owner: - | ||
| -- | ||
|
|
||
| CREATE INDEX index_delayed_jobs_on_run_at ON public.delayed_jobs USING btree (run_at) WHERE (locked_at IS NULL); | ||
|
|
||
|
|
||
| -- | ||
| -- PostgreSQL database dump complete | ||
| -- | ||
|
|
||
| SET search_path TO "$user", public; | ||
|
|
||
| INSERT INTO "schema_migrations" (version) VALUES | ||
| ('20240822225012'), | ||
| ('20240822224954'), | ||
| ('20240725043656'), | ||
| ('20240621041110'), | ||
| ('20240621020038'), | ||
| ('20220802204003'), | ||
| ('20211125055031'), | ||
| ('20211012054749'), | ||
| ('20210923052631'), | ||
| ('20210903003251'); | ||
|
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,78 @@ | ||
| SET statement_timeout = 0; | ||
| SET lock_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 client_min_messages = warning; | ||
|
|
||
| SET default_tablespace = ''; | ||
|
|
||
| -- Name: ar_internal_metadata; Type: TABLE | ||
|
|
||
| CREATE TABLE public.ar_internal_metadata ( | ||
| key character varying NOT NULL, | ||
| value character varying, | ||
| created_at timestamp(6) without time zone NOT NULL, | ||
| updated_at timestamp(6) without time zone NOT NULL | ||
| ); | ||
|
|
||
| -- Name: delayed_jobs; Type: TABLE | ||
|
|
||
| CREATE TABLE public.delayed_jobs ( | ||
| id BIGSERIAL PRIMARY KEY, | ||
| priority integer DEFAULT 0, | ||
| attempts integer DEFAULT 0, | ||
| handler text, | ||
| last_error text, | ||
| run_at timestamp without time zone, | ||
| locked_at timestamp without time zone, | ||
| failed_at timestamp without time zone, | ||
| locked_by character varying(255), | ||
| queue character varying(255), | ||
| created_at timestamp without time zone NOT NULL, | ||
| updated_at timestamp without time zone NOT NULL, | ||
| metadata jsonb DEFAULT '{}'::jsonb, | ||
| whodunnit text | ||
| ) | ||
| WITH (fillfactor='85'); | ||
|
|
||
| -- Name: schema_migrations; Type: TABLE | ||
|
|
||
| CREATE TABLE public.schema_migrations ( | ||
| version character varying NOT NULL | ||
| ); | ||
|
|
||
| ALTER TABLE ONLY public.ar_internal_metadata | ||
| ADD CONSTRAINT ar_internal_metadata_pkey PRIMARY KEY (key); | ||
|
|
||
| ALTER TABLE ONLY public.schema_migrations | ||
| ADD CONSTRAINT schema_migrations_pkey PRIMARY KEY (version); | ||
|
|
||
| -- Name: index_delayed_jobs_on_locked_by; Type: INDEX | ||
|
|
||
| CREATE INDEX index_delayed_jobs_on_locked_by ON public.delayed_jobs USING btree (locked_by); | ||
|
|
||
| -- Name: index_delayed_jobs_on_queue; Type: INDEX | ||
|
|
||
| CREATE INDEX index_delayed_jobs_on_queue ON public.delayed_jobs USING btree (queue); | ||
|
|
||
| -- Name: index_delayed_jobs_on_run_at; Type: INDEX | ||
|
|
||
| CREATE INDEX index_delayed_jobs_on_run_at ON public.delayed_jobs USING btree (run_at) WHERE (locked_at IS NULL); | ||
|
|
||
| -- PostgreSQL database dump complete | ||
|
|
||
| SET search_path TO "$user", public; | ||
|
|
||
| INSERT INTO "schema_migrations" (version) VALUES | ||
| ('20240822225012'), | ||
| ('20240822224954'), | ||
| ('20240725043656'), | ||
| ('20240621041110'), | ||
| ('20240621020038'), | ||
| ('20220802204003'), | ||
| ('20211125055031'), | ||
| ('20211012054749'), | ||
| ('20210923052631'), | ||
| ('20210903003251'); |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.

There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Test fails without this fix: