Skip to content

Commit 6bfcfd1

Browse files
committed
PRIMARY KEY only for table, FOREIGN TABLE not support it
1 parent 2dae69c commit 6bfcfd1

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

lib/activerecord-clean-db-structure/clean_dump.rb

+2-2
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@ def run
3030
# Reduce noise for id fields by making them SERIAL instead of integer+sequence stuff
3131
#
3232
# This is a bit optimistic, but works as long as you don't have an id field thats not a sequence/uuid
33-
dump.gsub!(/^ id integer NOT NULL,$/, ' id SERIAL PRIMARY KEY,')
34-
dump.gsub!(/^ id bigint NOT NULL,$/, ' id BIGSERIAL PRIMARY KEY,')
33+
dump.gsub!(/^CREATE TABLE (\w+) \(\n id integer NOT NULL,$/, "CREATE TABLE \\1 (\n id SERIAL PRIMARY KEY,")
34+
dump.gsub!(/^CREATE TABLE (\w+) \(\n id bigint NOT NULL,$/, "CREATE TABLE \\1 (\n id BIGSERIAL PRIMARY KEY,")
3535
dump.gsub!(/^ id uuid DEFAULT uuid_generate_v4\(\) NOT NULL,$/, ' id uuid DEFAULT uuid_generate_v4() PRIMARY KEY,')
3636
dump.gsub!(/^CREATE SEQUENCE \w+_id_seq\s+START WITH 1\s+INCREMENT BY 1\s+NO MINVALUE\s+NO MAXVALUE\s+CACHE 1;$/, '')
3737
dump.gsub!(/^ALTER SEQUENCE \w+_id_seq OWNED BY .*;$/, '')

0 commit comments

Comments
 (0)