Skip to content

Commit 562bfd2

Browse files
Support newer Postgresql version that use leading commas in versions list
1 parent fffb341 commit 562bfd2

File tree

6 files changed

+999
-0
lines changed

6 files changed

+999
-0
lines changed

lib/git-merge-structure-sql.rb

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,41 @@ def format_versions(versions)
7171
VARIANTS.unshift self
7272
end
7373

74+
module Postgresql # This covers PostgreSQL with leading commas
75+
RE_VERSION = /^[, ]\('(\d+)'\)\n/
76+
RE_VERSIONS = /^INSERT INTO (?<q>["`])schema_migrations\k<q> \(version\) VALUES\n\K#{RE_VERSION}+;/
77+
78+
class << self
79+
def match?(content)
80+
RE_VERSIONS === content
81+
end
82+
83+
def merge!(*contents)
84+
merge_versions!(*contents)
85+
end
86+
87+
private
88+
89+
def merge_versions!(*contents)
90+
replacement = format_versions(
91+
contents.inject([]) { |versions, content|
92+
versions | content[RE_VERSIONS].scan(RE_VERSION).flatten
93+
}.sort
94+
)
95+
96+
contents.each { |content|
97+
content.sub!(RE_VERSIONS, replacement)
98+
}
99+
end
100+
101+
def format_versions(versions)
102+
" " + versions.map { |version| "('%s')" % version }.join("\n,") << "\n;"
103+
end
104+
end
105+
106+
VARIANTS.unshift self
107+
end
108+
74109
module MySQL
75110
class << self
76111
RE_DUMP_TIMESTAMP = /^-- Dump completed on \K.+$/
Lines changed: 216 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,216 @@
1+
SET statement_timeout = 0;
2+
SET lock_timeout = 0;
3+
SET idle_in_transaction_session_timeout = 0;
4+
SET client_encoding = 'UTF8';
5+
SET standard_conforming_strings = on;
6+
SELECT pg_catalog.set_config('search_path', '', false);
7+
SET check_function_bodies = false;
8+
SET client_min_messages = warning;
9+
SET row_security = off;
10+
11+
--
12+
-- Name: plpgsql; Type: EXTENSION; Schema: -; Owner: -
13+
--
14+
15+
CREATE EXTENSION IF NOT EXISTS plpgsql WITH SCHEMA pg_catalog;
16+
17+
18+
--
19+
-- Name: EXTENSION plpgsql; Type: COMMENT; Schema: -; Owner: -
20+
--
21+
22+
COMMENT ON EXTENSION plpgsql IS 'PL/pgSQL procedural language';
23+
24+
25+
SET default_tablespace = '';
26+
27+
SET default_with_oids = false;
28+
29+
--
30+
-- Name: ar_internal_metadata; Type: TABLE; Schema: public; Owner: -
31+
--
32+
33+
CREATE TABLE public.ar_internal_metadata (
34+
key character varying NOT NULL,
35+
value character varying,
36+
created_at timestamp without time zone NOT NULL,
37+
updated_at timestamp without time zone NOT NULL
38+
);
39+
40+
41+
--
42+
-- Name: articles; Type: TABLE; Schema: public; Owner: -
43+
--
44+
45+
CREATE TABLE public.articles (
46+
id bigint NOT NULL,
47+
title character varying,
48+
content text,
49+
created_at timestamp without time zone NOT NULL,
50+
updated_at timestamp without time zone NOT NULL
51+
);
52+
53+
54+
--
55+
-- Name: articles_id_seq; Type: SEQUENCE; Schema: public; Owner: -
56+
--
57+
58+
CREATE SEQUENCE public.articles_id_seq
59+
START WITH 1
60+
INCREMENT BY 1
61+
NO MINVALUE
62+
NO MAXVALUE
63+
CACHE 1;
64+
65+
66+
--
67+
-- Name: articles_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: -
68+
--
69+
70+
ALTER SEQUENCE public.articles_id_seq OWNED BY public.articles.id;
71+
72+
73+
--
74+
-- Name: schema_migrations; Type: TABLE; Schema: public; Owner: -
75+
--
76+
77+
CREATE TABLE public.schema_migrations (
78+
version character varying NOT NULL
79+
);
80+
81+
82+
--
83+
-- Name: user_profiles; Type: TABLE; Schema: public; Owner: -
84+
--
85+
86+
CREATE TABLE public.user_profiles (
87+
id bigint NOT NULL,
88+
user_id integer,
89+
self_introduction text,
90+
created_at timestamp without time zone NOT NULL,
91+
updated_at timestamp without time zone NOT NULL
92+
);
93+
94+
95+
--
96+
-- Name: user_profiles_id_seq; Type: SEQUENCE; Schema: public; Owner: -
97+
--
98+
99+
CREATE SEQUENCE public.user_profiles_id_seq
100+
START WITH 1
101+
INCREMENT BY 1
102+
NO MINVALUE
103+
NO MAXVALUE
104+
CACHE 1;
105+
106+
107+
--
108+
-- Name: user_profiles_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: -
109+
--
110+
111+
ALTER SEQUENCE public.user_profiles_id_seq OWNED BY public.user_profiles.id;
112+
113+
114+
--
115+
-- Name: users; Type: TABLE; Schema: public; Owner: -
116+
--
117+
118+
CREATE TABLE public.users (
119+
id bigint NOT NULL,
120+
name character varying,
121+
created_at timestamp without time zone NOT NULL,
122+
updated_at timestamp without time zone NOT NULL
123+
);
124+
125+
126+
--
127+
-- Name: users_id_seq; Type: SEQUENCE; Schema: public; Owner: -
128+
--
129+
130+
CREATE SEQUENCE public.users_id_seq
131+
START WITH 1
132+
INCREMENT BY 1
133+
NO MINVALUE
134+
NO MAXVALUE
135+
CACHE 1;
136+
137+
138+
--
139+
-- Name: users_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: -
140+
--
141+
142+
ALTER SEQUENCE public.users_id_seq OWNED BY public.users.id;
143+
144+
145+
--
146+
-- Name: articles id; Type: DEFAULT; Schema: public; Owner: -
147+
--
148+
149+
ALTER TABLE ONLY public.articles ALTER COLUMN id SET DEFAULT nextval('public.articles_id_seq'::regclass);
150+
151+
152+
--
153+
-- Name: user_profiles id; Type: DEFAULT; Schema: public; Owner: -
154+
--
155+
156+
ALTER TABLE ONLY public.user_profiles ALTER COLUMN id SET DEFAULT nextval('public.user_profiles_id_seq'::regclass);
157+
158+
159+
--
160+
-- Name: users id; Type: DEFAULT; Schema: public; Owner: -
161+
--
162+
163+
ALTER TABLE ONLY public.users ALTER COLUMN id SET DEFAULT nextval('public.users_id_seq'::regclass);
164+
165+
166+
--
167+
-- Name: ar_internal_metadata ar_internal_metadata_pkey; Type: CONSTRAINT; Schema: public; Owner: -
168+
--
169+
170+
ALTER TABLE ONLY public.ar_internal_metadata
171+
ADD CONSTRAINT ar_internal_metadata_pkey PRIMARY KEY (key);
172+
173+
174+
--
175+
-- Name: articles articles_pkey; Type: CONSTRAINT; Schema: public; Owner: -
176+
--
177+
178+
ALTER TABLE ONLY public.articles
179+
ADD CONSTRAINT articles_pkey PRIMARY KEY (id);
180+
181+
182+
--
183+
-- Name: schema_migrations schema_migrations_pkey; Type: CONSTRAINT; Schema: public; Owner: -
184+
--
185+
186+
ALTER TABLE ONLY public.schema_migrations
187+
ADD CONSTRAINT schema_migrations_pkey PRIMARY KEY (version);
188+
189+
190+
--
191+
-- Name: user_profiles user_profiles_pkey; Type: CONSTRAINT; Schema: public; Owner: -
192+
--
193+
194+
ALTER TABLE ONLY public.user_profiles
195+
ADD CONSTRAINT user_profiles_pkey PRIMARY KEY (id);
196+
197+
198+
--
199+
-- Name: users users_pkey; Type: CONSTRAINT; Schema: public; Owner: -
200+
--
201+
202+
ALTER TABLE ONLY public.users
203+
ADD CONSTRAINT users_pkey PRIMARY KEY (id);
204+
205+
206+
--
207+
-- PostgreSQL database dump complete
208+
--
209+
210+
SET search_path TO "$user", public;
211+
212+
INSERT INTO "schema_migrations" (version) VALUES
213+
('20181129162731')
214+
,('20181129163134')
215+
,('20181129163626')
216+
;

0 commit comments

Comments
 (0)