@@ -28,37 +28,14 @@ def run
28
28
dump . gsub! ( /^--$/ , '' )
29
29
30
30
# Mask user mapping
31
- dump . gsub! (
32
- /^CREATE USER MAPPING FOR \w + SERVER (\w +) .*;/m ,
33
- 'CREATE USER MAPPING FOR some_user SERVER \1;'
34
- )
35
- dump . gsub! (
36
- /^-- Name: USER MAPPING \w + SERVER (\w +); Type: USER MAPPING/ ,
37
- '-- Name: USER MAPPING some_user SERVER \1; Type: USER MAPPING'
38
- )
31
+ dump . gsub! ( /^CREATE USER MAPPING FOR \w + SERVER (\w +) .*?;/m , 'CREATE USER MAPPING FOR some_user SERVER \1;' )
32
+ dump . gsub! ( /^-- Name: USER MAPPING \w + SERVER (\w +); Type: USER MAPPING/ , '-- Name: USER MAPPING some_user SERVER \1; Type: USER MAPPING' )
39
33
40
34
# Reduce noise for id fields by making them SERIAL instead of integer+sequence stuff
41
35
#
42
36
# This is a bit optimistic, but works as long as you don't have an id field thats not a sequence/uuid
43
- is_table = false , count_open_brackets = 0 , count_close_brackets = 0
44
- @dump = dump . lines . map do |line |
45
- is_table = true if line =~ /CREATE TABLE (\w +) \( /
46
-
47
- count_open_brackets += line . count ( '(' )
48
- count_close_brackets += line . count ( ')' )
49
-
50
- is_table = false if is_table && count_open_brackets == count_close_brackets
51
-
52
- if !is_table # optimization speed
53
- line
54
- elsif line =~ /^ id integer NOT NULL/
55
- line . sub ( 'id integer NOT NULL' , 'id SERIAL PRIMARY KEY' )
56
- elsif line =~ /^ id bigint NOT NULL/
57
- line . sub ( 'id bigint NOT NULL' , 'id BIGSERIAL PRIMARY KEY' )
58
- else
59
- line
60
- end
61
- end . join
37
+ dump . gsub! ( /^CREATE TABLE (\w +) \( \n id integer NOT NULL(.*?);/m , "CREATE TABLE \\ 1 (\n id SERIAL PRIMARY KEY\\ 2;" )
38
+ dump . gsub! ( /^CREATE TABLE (\w +) \( \n id bigint NOT NULL(.*?);/m , "CREATE TABLE \\ 1 (\n id BIGSERIAL PRIMARY KEY\\ 2;" )
62
39
63
40
dump . gsub! ( /^ id uuid DEFAULT uuid_generate_v4\( \) NOT NULL,$/ , ' id uuid DEFAULT uuid_generate_v4() PRIMARY KEY,' )
64
41
dump . gsub! ( /^CREATE SEQUENCE \w +_id_seq\s +START WITH 1\s +INCREMENT BY 1\s +NO MINVALUE\s +NO MAXVALUE\s +CACHE 1;$/ , '' )
0 commit comments