Skip to content

Commit

Permalink
add: e2e tests
Browse files Browse the repository at this point in the history
  • Loading branch information
alexisvisco committed May 27, 2024
1 parent 474424d commit 13aceee
Show file tree
Hide file tree
Showing 7 changed files with 284 additions and 1 deletion.
5 changes: 4 additions & 1 deletion pkg/schema/pg/enum.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,10 @@ func (s *Schema) CreateEnum(name string, values []string, opts ...schema.CreateE
options.Values = values

if s.Context.MigrationDirection == types.MigrationDirectionDown {
s.rollbackMode().DropEnum(name)
s.rollbackMode().DropEnum(name, schema.DropEnumOptions{
Schema: options.Schema,
IfExists: true,
})
return
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
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;

--
-- Name: migrations_with_change; Type: SCHEMA; Schema: -; Owner: -
--

CREATE SCHEMA migrations_with_change;


--
-- Name: status; Type: TYPE; Schema: migrations_with_change; Owner: -
--

CREATE TYPE migrations_with_change.status AS ENUM (
'active',
'inactive'
);


SET default_table_access_method = heap;

--
-- Name: mig_schema_versions; Type: TABLE; Schema: migrations_with_change; Owner: -
--

CREATE TABLE migrations_with_change.mig_schema_versions (
id text NOT NULL
);


--
-- Name: users; Type: TABLE; Schema: migrations_with_change; Owner: -
--

CREATE TABLE migrations_with_change.users (
id integer NOT NULL,
name text,
email text,
created_at timestamp(6) without time zone DEFAULT now() NOT NULL,
updated_at timestamp(6) without time zone DEFAULT now() NOT NULL
);


--
-- Name: users_id_seq; Type: SEQUENCE; Schema: migrations_with_change; Owner: -
--

CREATE SEQUENCE migrations_with_change.users_id_seq
AS integer
START WITH 1
INCREMENT BY 1
NO MINVALUE
NO MAXVALUE
CACHE 1;


--
-- Name: users_id_seq; Type: SEQUENCE OWNED BY; Schema: migrations_with_change; Owner: -
--

ALTER SEQUENCE migrations_with_change.users_id_seq OWNED BY migrations_with_change.users.id;


--
-- Name: users id; Type: DEFAULT; Schema: migrations_with_change; Owner: -
--

ALTER TABLE ONLY migrations_with_change.users ALTER COLUMN id SET DEFAULT nextval('migrations_with_change.users_id_seq'::regclass);


--
-- Name: mig_schema_versions mig_schema_versions_pkey; Type: CONSTRAINT; Schema: migrations_with_change; Owner: -
--

ALTER TABLE ONLY migrations_with_change.mig_schema_versions
ADD CONSTRAINT mig_schema_versions_pkey PRIMARY KEY (id);


--
-- Name: users users_pkey; Type: CONSTRAINT; Schema: migrations_with_change; Owner: -
--

ALTER TABLE ONLY migrations_with_change.users
ADD CONSTRAINT users_pkey PRIMARY KEY (id);


--
-- Name: idx_users_email; Type: INDEX; Schema: migrations_with_change; Owner: -
--

CREATE UNIQUE INDEX idx_users_email ON migrations_with_change.users USING btree (email);


--
-- Name: idx_users_name; Type: INDEX; Schema: migrations_with_change; Owner: -
--

CREATE INDEX idx_users_name ON migrations_with_change.users USING btree (name);


--
-- PostgreSQL database dump complete
--

Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
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;

--
-- Name: migrations_with_classic; Type: SCHEMA; Schema: -; Owner: -
--

CREATE SCHEMA migrations_with_classic;


--
-- Name: status; Type: TYPE; Schema: migrations_with_classic; Owner: -
--

CREATE TYPE migrations_with_classic.status AS ENUM (
'active',
'inactive'
);


SET default_table_access_method = heap;

--
-- Name: mig_schema_versions; Type: TABLE; Schema: migrations_with_classic; Owner: -
--

CREATE TABLE migrations_with_classic.mig_schema_versions (
id text NOT NULL
);


--
-- Name: users; Type: TABLE; Schema: migrations_with_classic; Owner: -
--

CREATE TABLE migrations_with_classic.users (
id integer NOT NULL,
name text,
email text,
created_at timestamp(6) without time zone DEFAULT now() NOT NULL,
updated_at timestamp(6) without time zone DEFAULT now() NOT NULL
);


--
-- Name: users_id_seq; Type: SEQUENCE; Schema: migrations_with_classic; Owner: -
--

CREATE SEQUENCE migrations_with_classic.users_id_seq
AS integer
START WITH 1
INCREMENT BY 1
NO MINVALUE
NO MAXVALUE
CACHE 1;


--
-- Name: users_id_seq; Type: SEQUENCE OWNED BY; Schema: migrations_with_classic; Owner: -
--

ALTER SEQUENCE migrations_with_classic.users_id_seq OWNED BY migrations_with_classic.users.id;


--
-- Name: users id; Type: DEFAULT; Schema: migrations_with_classic; Owner: -
--

ALTER TABLE ONLY migrations_with_classic.users ALTER COLUMN id SET DEFAULT nextval('migrations_with_classic.users_id_seq'::regclass);


--
-- Name: mig_schema_versions mig_schema_versions_pkey; Type: CONSTRAINT; Schema: migrations_with_classic; Owner: -
--

ALTER TABLE ONLY migrations_with_classic.mig_schema_versions
ADD CONSTRAINT mig_schema_versions_pkey PRIMARY KEY (id);


--
-- Name: users users_pkey; Type: CONSTRAINT; Schema: migrations_with_classic; Owner: -
--

ALTER TABLE ONLY migrations_with_classic.users
ADD CONSTRAINT users_pkey PRIMARY KEY (id);


--
-- Name: idx_users_email; Type: INDEX; Schema: migrations_with_classic; Owner: -
--

CREATE UNIQUE INDEX idx_users_email ON migrations_with_classic.users USING btree (email);


--
-- Name: idx_users_name; Type: INDEX; Schema: migrations_with_classic; Owner: -
--

CREATE INDEX idx_users_name ON migrations_with_classic.users USING btree (name);


--
-- PostgreSQL database dump complete
--

24 changes: 24 additions & 0 deletions testdata/e2e/pg/migrations_with_change/20240527192300_enum.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package migrations

import (
"github.com/alexisvisco/amigo/pkg/schema"
"github.com/alexisvisco/amigo/pkg/schema/pg"
"time"
)

type Migration20240527192300Enum struct{}

func (m Migration20240527192300Enum) Change(s *pg.Schema) {
s.CreateEnum("status", []string{"active", "inactive"}, schema.CreateEnumOptions{
Schema: "migrations_with_change",
})
}

func (m Migration20240527192300Enum) Name() string {
return "enum"
}

func (m Migration20240527192300Enum) Date() time.Time {
t, _ := time.Parse(time.RFC3339, "2024-05-27T21:23:00+02:00")
return t
}
1 change: 1 addition & 0 deletions testdata/e2e/pg/migrations_with_change/migrations.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,5 @@ var Migrations = []schema.Migration{
&Migration20240518071740CreateUser{},
&Migration20240518071842AddIndexUserEmail{},
&Migration20240518071938CustomSeed{},
&Migration20240527192300Enum{},
}
28 changes: 28 additions & 0 deletions testdata/e2e/pg/migrations_with_classic/20240527192355_enum.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package migrations

import (
"github.com/alexisvisco/amigo/pkg/schema"
"github.com/alexisvisco/amigo/pkg/schema/pg"
"time"
)

type Migration20240527192355Enum struct{}

func (m Migration20240527192355Enum) Up(s *pg.Schema) {
s.CreateEnum("status", []string{"active", "inactive"}, schema.CreateEnumOptions{
Schema: "migrations_with_classic",
})
}

func (m Migration20240527192355Enum) Down(s *pg.Schema) {
s.DropEnum("status", schema.DropEnumOptions{Schema: "migrations_with_classic"})
}

func (m Migration20240527192355Enum) Name() string {
return "enum"
}

func (m Migration20240527192355Enum) Date() time.Time {
t, _ := time.Parse(time.RFC3339, "2024-05-27T21:23:55+02:00")
return t
}
1 change: 1 addition & 0 deletions testdata/e2e/pg/migrations_with_classic/migrations.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,5 @@ var Migrations = []schema.Migration{
&Migration20240518071740CreateUser{},
&Migration20240518071842AddIndexUserEmail{},
&Migration20240518071938CustomSeed{},
&Migration20240527192355Enum{},
}

0 comments on commit 13aceee

Please sign in to comment.