Skip to content

Commit

Permalink
Improve rename_column SQLite behavior (#95)
Browse files Browse the repository at this point in the history
* Add failing test case for rename_column

* Improve rename_column SQLite behavior

`ALTER TABLE .. RENAME COLUMN .. TO ..` is officially supported and does not need the temporary table workaround.
  • Loading branch information
aeneasr committed Jul 6, 2020
1 parent c8d2f47 commit 4e9fb9c
Show file tree
Hide file tree
Showing 42 changed files with 561 additions and 81 deletions.
1 change: 1 addition & 0 deletions internal/e2e/fixtures/postgres/down/1.sql
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ SET default_tablespace = '';

CREATE TABLE public.e2e_users (
id uuid NOT NULL,
username character varying(255),
created_at timestamp without time zone NOT NULL,
updated_at timestamp without time zone NOT NULL
);
Expand Down
3 changes: 2 additions & 1 deletion internal/e2e/fixtures/postgres/down/2.sql
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ SET default_tablespace = '';

CREATE TABLE public.e2e_user_notes (
id uuid NOT NULL,
notes character varying(255),
user_id uuid NOT NULL,
notes character varying(255),
title character varying(64) DEFAULT ''::character varying NOT NULL
);

Expand All @@ -38,6 +38,7 @@ ALTER TABLE public.e2e_user_notes OWNER TO postgres;

CREATE TABLE public.e2e_users (
id uuid NOT NULL,
username character varying(255),
created_at timestamp without time zone NOT NULL,
updated_at timestamp without time zone NOT NULL
);
Expand Down
5 changes: 3 additions & 2 deletions internal/e2e/fixtures/postgres/down/3.sql
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ SET default_tablespace = '';

CREATE TABLE public.e2e_user_notes (
id uuid NOT NULL,
notes character varying(255),
user_id uuid NOT NULL
user_id uuid NOT NULL,
notes character varying(255)
);


Expand All @@ -37,6 +37,7 @@ ALTER TABLE public.e2e_user_notes OWNER TO postgres;

CREATE TABLE public.e2e_users (
id uuid NOT NULL,
username character varying(255),
created_at timestamp without time zone NOT NULL,
updated_at timestamp without time zone NOT NULL
);
Expand Down
5 changes: 3 additions & 2 deletions internal/e2e/fixtures/postgres/down/4.sql
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ SET default_tablespace = '';

CREATE TABLE public.e2e_user_notes (
id uuid NOT NULL,
notes character varying(255),
user_id uuid NOT NULL,
slug character varying(64) NOT NULL
slug character varying(64) NOT NULL,
notes character varying(255)
);


Expand All @@ -38,6 +38,7 @@ ALTER TABLE public.e2e_user_notes OWNER TO postgres;

CREATE TABLE public.e2e_users (
id uuid NOT NULL,
username character varying(255),
created_at timestamp without time zone NOT NULL,
updated_at timestamp without time zone NOT NULL
);
Expand Down
5 changes: 3 additions & 2 deletions internal/e2e/fixtures/postgres/down/5.sql
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ SET default_tablespace = '';

CREATE TABLE public.e2e_user_notes (
id uuid NOT NULL,
notes character varying(255),
user_id uuid NOT NULL,
slug character varying(64) NOT NULL
slug character varying(64) NOT NULL,
notes character varying(255)
);


Expand All @@ -38,6 +38,7 @@ ALTER TABLE public.e2e_user_notes OWNER TO postgres;

CREATE TABLE public.e2e_users (
id uuid NOT NULL,
username character varying(255),
created_at timestamp without time zone NOT NULL,
updated_at timestamp without time zone NOT NULL
);
Expand Down
5 changes: 3 additions & 2 deletions internal/e2e/fixtures/postgres/down/6.sql
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ SET default_tablespace = '';

CREATE TABLE public.e2e_user_notes (
id uuid NOT NULL,
notes character varying(255),
user_id uuid NOT NULL,
slug character varying(64) NOT NULL
slug character varying(64) NOT NULL,
notes character varying(255)
);


Expand All @@ -38,6 +38,7 @@ ALTER TABLE public.e2e_user_notes OWNER TO postgres;

CREATE TABLE public.e2e_users (
id uuid NOT NULL,
username character varying(255),
created_at timestamp without time zone NOT NULL,
updated_at timestamp without time zone NOT NULL
);
Expand Down
108 changes: 108 additions & 0 deletions internal/e2e/fixtures/postgres/down/7.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
--
-- PostgreSQL database dump
--

-- Dumped from database version 9.6.18
-- Dumped by pg_dump version 12.3

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;

SET default_tablespace = '';

--
-- Name: e2e_user_posts; Type: TABLE; Schema: public; Owner: postgres
--

CREATE TABLE public.e2e_user_posts (
id uuid NOT NULL,
user_id uuid NOT NULL,
slug character varying(64) NOT NULL,
notes character varying(255)
);


ALTER TABLE public.e2e_user_posts OWNER TO postgres;

--
-- Name: e2e_users; Type: TABLE; Schema: public; Owner: postgres
--

CREATE TABLE public.e2e_users (
id uuid NOT NULL,
username character varying(255),
created_at timestamp without time zone NOT NULL,
updated_at timestamp without time zone NOT NULL
);


ALTER TABLE public.e2e_users OWNER TO postgres;

--
-- Name: schema_migration; Type: TABLE; Schema: public; Owner: postgres
--

CREATE TABLE public.schema_migration (
version character varying(14) NOT NULL
);


ALTER TABLE public.schema_migration OWNER TO postgres;

--
-- Name: e2e_user_posts e2e_user_notes_pkey; Type: CONSTRAINT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY public.e2e_user_posts
ADD CONSTRAINT e2e_user_notes_pkey PRIMARY KEY (id);


--
-- Name: e2e_users e2e_users_pkey; Type: CONSTRAINT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY public.e2e_users
ADD CONSTRAINT e2e_users_pkey PRIMARY KEY (id);


--
-- Name: e2e_user_notes_slug_idx; Type: INDEX; Schema: public; Owner: postgres
--

CREATE UNIQUE INDEX e2e_user_notes_slug_idx ON public.e2e_user_posts USING btree (slug);


--
-- Name: e2e_user_notes_user_id_idx; Type: INDEX; Schema: public; Owner: postgres
--

CREATE INDEX e2e_user_notes_user_id_idx ON public.e2e_user_posts USING btree (user_id);


--
-- Name: schema_migration_version_idx; Type: INDEX; Schema: public; Owner: postgres
--

CREATE UNIQUE INDEX schema_migration_version_idx ON public.schema_migration USING btree (version);


--
-- Name: e2e_user_posts e2e_user_notes_user_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY public.e2e_user_posts
ADD CONSTRAINT e2e_user_notes_user_id_fkey FOREIGN KEY (user_id) REFERENCES public.e2e_users(id) ON DELETE CASCADE;


--
-- PostgreSQL database dump complete
--

108 changes: 108 additions & 0 deletions internal/e2e/fixtures/postgres/down/8.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
--
-- PostgreSQL database dump
--

-- Dumped from database version 9.6.18
-- Dumped by pg_dump version 12.3

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;

SET default_tablespace = '';

--
-- Name: e2e_user_posts; Type: TABLE; Schema: public; Owner: postgres
--

CREATE TABLE public.e2e_user_posts (
id uuid NOT NULL,
user_id uuid NOT NULL,
slug character varying(64) NOT NULL,
content character varying(255) DEFAULT ''::character varying NOT NULL
);


ALTER TABLE public.e2e_user_posts OWNER TO postgres;

--
-- Name: e2e_users; Type: TABLE; Schema: public; Owner: postgres
--

CREATE TABLE public.e2e_users (
id uuid NOT NULL,
username character varying(255),
created_at timestamp without time zone NOT NULL,
updated_at timestamp without time zone NOT NULL
);


ALTER TABLE public.e2e_users OWNER TO postgres;

--
-- Name: schema_migration; Type: TABLE; Schema: public; Owner: postgres
--

CREATE TABLE public.schema_migration (
version character varying(14) NOT NULL
);


ALTER TABLE public.schema_migration OWNER TO postgres;

--
-- Name: e2e_user_posts e2e_user_notes_pkey; Type: CONSTRAINT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY public.e2e_user_posts
ADD CONSTRAINT e2e_user_notes_pkey PRIMARY KEY (id);


--
-- Name: e2e_users e2e_users_pkey; Type: CONSTRAINT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY public.e2e_users
ADD CONSTRAINT e2e_users_pkey PRIMARY KEY (id);


--
-- Name: e2e_user_notes_slug_idx; Type: INDEX; Schema: public; Owner: postgres
--

CREATE UNIQUE INDEX e2e_user_notes_slug_idx ON public.e2e_user_posts USING btree (slug);


--
-- Name: e2e_user_notes_user_id_idx; Type: INDEX; Schema: public; Owner: postgres
--

CREATE INDEX e2e_user_notes_user_id_idx ON public.e2e_user_posts USING btree (user_id);


--
-- Name: schema_migration_version_idx; Type: INDEX; Schema: public; Owner: postgres
--

CREATE UNIQUE INDEX schema_migration_version_idx ON public.schema_migration USING btree (version);


--
-- Name: e2e_user_posts e2e_user_notes_user_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: postgres
--

ALTER TABLE ONLY public.e2e_user_posts
ADD CONSTRAINT e2e_user_notes_user_id_fkey FOREIGN KEY (user_id) REFERENCES public.e2e_users(id) ON DELETE CASCADE;


--
-- PostgreSQL database dump complete
--

1 change: 1 addition & 0 deletions internal/e2e/fixtures/postgres/up/0.sql
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ SET default_tablespace = '';

CREATE TABLE public.e2e_users (
id uuid NOT NULL,
username character varying(255),
created_at timestamp without time zone NOT NULL,
updated_at timestamp without time zone NOT NULL
);
Expand Down
1 change: 1 addition & 0 deletions internal/e2e/fixtures/postgres/up/1.sql
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ ALTER TABLE public.e2e_user_notes OWNER TO postgres;

CREATE TABLE public.e2e_users (
id uuid NOT NULL,
username character varying(255),
created_at timestamp without time zone NOT NULL,
updated_at timestamp without time zone NOT NULL
);
Expand Down
1 change: 1 addition & 0 deletions internal/e2e/fixtures/postgres/up/2.sql
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ ALTER TABLE public.e2e_user_notes OWNER TO postgres;

CREATE TABLE public.e2e_users (
id uuid NOT NULL,
username character varying(255),
created_at timestamp without time zone NOT NULL,
updated_at timestamp without time zone NOT NULL
);
Expand Down
1 change: 1 addition & 0 deletions internal/e2e/fixtures/postgres/up/3.sql
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ ALTER TABLE public.e2e_user_notes OWNER TO postgres;

CREATE TABLE public.e2e_users (
id uuid NOT NULL,
username character varying(255),
created_at timestamp without time zone NOT NULL,
updated_at timestamp without time zone NOT NULL
);
Expand Down
1 change: 1 addition & 0 deletions internal/e2e/fixtures/postgres/up/4.sql
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ ALTER TABLE public.e2e_user_notes OWNER TO postgres;

CREATE TABLE public.e2e_users (
id uuid NOT NULL,
username character varying(255),
created_at timestamp without time zone NOT NULL,
updated_at timestamp without time zone NOT NULL
);
Expand Down
1 change: 1 addition & 0 deletions internal/e2e/fixtures/postgres/up/5.sql
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ ALTER TABLE public.e2e_user_notes OWNER TO postgres;

CREATE TABLE public.e2e_users (
id uuid NOT NULL,
username character varying(255),
created_at timestamp without time zone NOT NULL,
updated_at timestamp without time zone NOT NULL
);
Expand Down
1 change: 1 addition & 0 deletions internal/e2e/fixtures/postgres/up/6.sql
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ ALTER TABLE public.e2e_user_posts OWNER TO postgres;

CREATE TABLE public.e2e_users (
id uuid NOT NULL,
username character varying(255),
created_at timestamp without time zone NOT NULL,
updated_at timestamp without time zone NOT NULL
);
Expand Down

0 comments on commit 4e9fb9c

Please sign in to comment.