@@ -38,24 +38,24 @@ def run
38
38
# This is a bit optimistic, but works as long as you don't have an id field thats not a sequence/uuid
39
39
dump . gsub! ( /^ id integer NOT NULL(,)?$/ , ' id SERIAL PRIMARY KEY\1' )
40
40
dump . gsub! ( /^ id bigint NOT NULL(,)?$/ , ' id BIGSERIAL PRIMARY KEY\1' )
41
- dump . gsub! ( /^ id uuid DEFAULT uuid_generate_v4\( \) NOT NULL(,)?$/ , ' id uuid DEFAULT uuid_generate_v4 () PRIMARY KEY\1 ' )
42
- dump . gsub! ( /^ id uuid DEFAULT gen_random_uuid\( \) NOT NULL(,)?$/ , ' id uuid DEFAULT gen_random_uuid () PRIMARY KEY\1 ' )
43
- dump . gsub! ( /^CREATE SEQUENCE \w +_id_seq\s +(AS integer\s +)?START WITH 1\s +INCREMENT BY 1\s +NO MINVALUE\s +NO MAXVALUE\s +CACHE 1;$/ , '' )
44
- dump . gsub! ( /^ALTER SEQUENCE \w +_id_seq OWNED BY .*;$/ , '' )
45
- dump . gsub! ( /^ALTER TABLE ONLY \w + ALTER COLUMN id SET DEFAULT nextval\( '\w +_id_seq'::regclass\) ;$/ , '' )
46
- dump . gsub! ( /^ALTER TABLE ONLY \w +\s +ADD CONSTRAINT \w +_pkey PRIMARY KEY \( id\) ;$/ , '' )
41
+ dump . gsub! ( /^ id uuid DEFAULT (public \. )? uuid_generate_v4\( \) NOT NULL(,)?$/ , ' id uuid DEFAULT \1uuid_generate_v4 () PRIMARY KEY\2 ' )
42
+ dump . gsub! ( /^ id uuid DEFAULT (public \. )? gen_random_uuid\( \) NOT NULL(,)?$/ , ' id uuid DEFAULT \1gen_random_uuid () PRIMARY KEY\2 ' )
43
+ dump . gsub! ( /^CREATE SEQUENCE [ \w \. ] +_id_seq\s +(AS integer\s +)?START WITH 1\s +INCREMENT BY 1\s +NO MINVALUE\s +NO MAXVALUE\s +CACHE 1;$/ , '' )
44
+ dump . gsub! ( /^ALTER SEQUENCE [ \w \. ] +_id_seq OWNED BY .*;$/ , '' )
45
+ dump . gsub! ( /^ALTER TABLE ONLY [ \w \. ] + ALTER COLUMN id SET DEFAULT nextval\( '[ \w \. ] +_id_seq'::regclass\) ;$/ , '' )
46
+ dump . gsub! ( /^ALTER TABLE ONLY [ \w \. ] +\s +ADD CONSTRAINT [ \w \. ] +_pkey PRIMARY KEY \( id\) ;$/ , '' )
47
47
dump . gsub! ( /^-- Name: (\w +\s +)?id; Type: DEFAULT$/ , '' )
48
48
dump . gsub! ( /^-- .*_id_seq; Type: SEQUENCE.*/ , '' )
49
49
dump . gsub! ( /^-- Name: (\w +\s +)?\w +_pkey; Type: CONSTRAINT$/ , '' )
50
50
51
51
# Remove inherited tables
52
- inherited_tables_regexp = /-- Name: ([\w _]+); Type: TABLE\n \n [^;]+?INHERITS \( [\w _]+\) ;/m
52
+ inherited_tables_regexp = /-- Name: ([\w _\. ]+); Type: TABLE\n \n [^;]+?INHERITS \( [\w _\. ]+\) ;/m
53
53
inherited_tables = dump . scan ( inherited_tables_regexp ) . map ( &:first )
54
54
dump . gsub! ( inherited_tables_regexp , '' )
55
55
inherited_tables . each do |inherited_table |
56
- dump . gsub! ( /ALTER TABLE ONLY #{ inherited_table } [^;]+;/ , '' )
56
+ dump . gsub! ( /ALTER TABLE ONLY (public \. )? #{ inherited_table } [^;]+;/ , '' )
57
57
58
- index_regexp = /CREATE INDEX ([\w _]+) ON #{ inherited_table } [^;]+;/m
58
+ index_regexp = /CREATE INDEX ([\w _]+) ON (public \. )? #{ inherited_table } [^;]+;/m
59
59
dump . scan ( index_regexp ) . map ( &:first ) . each do |inherited_table_index |
60
60
dump . gsub! ( "-- Name: #{ inherited_table_index } ; Type: INDEX" , '' )
61
61
end
0 commit comments