Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test(endtoend): Split shema and queries #2803

Merged
merged 3 commits into from
Oct 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
5 changes: 1 addition & 4 deletions internal/endtoend/ddl_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,11 +92,8 @@ func TestValidSchema(t *testing.T) {
if err != nil {
t.Fatalf("%s: %s", f, err)
}
// TODO: Split schema into separate files
before, _, _ := strings.Cut(string(contents), "-- name:")
before, _, _ = strings.Cut(before, "/* name:")
// Support loading pg_dump SQL files
before = strings.ReplaceAll(before, "CREATE SCHEMA public;", "CREATE SCHEMA IF NOT EXISTS public;")
before := strings.ReplaceAll(string(contents), "CREATE SCHEMA public;", "CREATE SCHEMA IF NOT EXISTS public;")
sqls = append(sqls, migrations.RemoveRollbackStatements(before))
}

Expand Down
2 changes: 0 additions & 2 deletions internal/endtoend/testdata/alias/mysql/query.sql
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
CREATE TABLE bar (id serial not null);

-- name: AliasBar :exec
DELETE FROM bar b
WHERE b.id = ?;
2 changes: 2 additions & 0 deletions internal/endtoend/testdata/alias/mysql/schema.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
CREATE TABLE bar (id serial not null);

2 changes: 1 addition & 1 deletion internal/endtoend/testdata/alias/mysql/sqlc.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"path": "go",
"engine": "mysql",
"name": "querytest",
"schema": "query.sql",
"schema": "schema.sql",
"queries": "query.sql"
}
]
Expand Down
2 changes: 0 additions & 2 deletions internal/endtoend/testdata/alias/postgresql/pgx/v4/query.sql
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
CREATE TABLE bar (id serial not null);

-- name: AliasBar :exec
DELETE FROM bar b
WHERE b.id = $1;
2 changes: 2 additions & 0 deletions internal/endtoend/testdata/alias/postgresql/pgx/v4/schema.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
CREATE TABLE bar (id serial not null);

Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"engine": "postgresql",
"sql_package": "pgx/v4",
"name": "querytest",
"schema": "query.sql",
"schema": "schema.sql",
"queries": "query.sql"
}
]
Expand Down
2 changes: 0 additions & 2 deletions internal/endtoend/testdata/alias/postgresql/pgx/v5/query.sql
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
CREATE TABLE bar (id serial not null);

-- name: AliasBar :exec
DELETE FROM bar b
WHERE b.id = $1;
2 changes: 2 additions & 0 deletions internal/endtoend/testdata/alias/postgresql/pgx/v5/schema.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
CREATE TABLE bar (id serial not null);

Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"engine": "postgresql",
"sql_package": "pgx/v5",
"name": "querytest",
"schema": "query.sql",
"schema": "schema.sql",
"queries": "query.sql"
}
]
Expand Down
2 changes: 0 additions & 2 deletions internal/endtoend/testdata/alias/postgresql/stdlib/query.sql
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
CREATE TABLE bar (id serial not null);

-- name: AliasBar :exec
DELETE FROM bar b
WHERE b.id = $1;
2 changes: 2 additions & 0 deletions internal/endtoend/testdata/alias/postgresql/stdlib/schema.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
CREATE TABLE bar (id serial not null);

Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"path": "go",
"engine": "postgresql",
"name": "querytest",
"schema": "query.sql",
"schema": "schema.sql",
"queries": "query.sql"
}
]
Expand Down
2 changes: 0 additions & 2 deletions internal/endtoend/testdata/alias/sqlite/query.sql
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
CREATE TABLE bar (id integer NOT NULL PRIMARY KEY AUTOINCREMENT);

-- name: AliasBar :exec
DELETE FROM bar AS b
WHERE b.id = ?;
2 changes: 2 additions & 0 deletions internal/endtoend/testdata/alias/sqlite/schema.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
CREATE TABLE bar (id integer NOT NULL PRIMARY KEY AUTOINCREMENT);

2 changes: 1 addition & 1 deletion internal/endtoend/testdata/alias/sqlite/sqlc.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"path": "go",
"engine": "sqlite",
"name": "querytest",
"schema": "query.sql",
"schema": "schema.sql",
"queries": "query.sql"
}
]
Expand Down
2 changes: 0 additions & 2 deletions internal/endtoend/testdata/any/pgx/v4/query.sql
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
CREATE TABLE bar (id bigserial not null);

-- name: Any :many
SELECT id
FROM bar
Expand Down
2 changes: 2 additions & 0 deletions internal/endtoend/testdata/any/pgx/v4/schema.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
CREATE TABLE bar (id bigserial not null);

2 changes: 1 addition & 1 deletion internal/endtoend/testdata/any/pgx/v4/sqlc.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"engine": "postgresql",
"sql_package": "pgx/v4",
"name": "querytest",
"schema": "query.sql",
"schema": "schema.sql",
"queries": "query.sql"
}
]
Expand Down
2 changes: 0 additions & 2 deletions internal/endtoend/testdata/any/pgx/v5/query.sql
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
CREATE TABLE bar (id bigserial not null);

-- name: Any :many
SELECT id
FROM bar
Expand Down
2 changes: 2 additions & 0 deletions internal/endtoend/testdata/any/pgx/v5/schema.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
CREATE TABLE bar (id bigserial not null);

2 changes: 1 addition & 1 deletion internal/endtoend/testdata/any/pgx/v5/sqlc.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"engine": "postgresql",
"sql_package": "pgx/v5",
"name": "querytest",
"schema": "query.sql",
"schema": "schema.sql",
"queries": "query.sql"
}
]
Expand Down
2 changes: 0 additions & 2 deletions internal/endtoend/testdata/any/stdlib/query.sql
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
CREATE TABLE bar (id bigserial not null);

-- name: Any :many
SELECT id
FROM bar
Expand Down
2 changes: 2 additions & 0 deletions internal/endtoend/testdata/any/stdlib/schema.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
CREATE TABLE bar (id bigserial not null);

2 changes: 1 addition & 1 deletion internal/endtoend/testdata/any/stdlib/sqlc.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
{
"path": "go",
"name": "querytest",
"schema": "query.sql",
"schema": "schema.sql",
"queries": "query.sql"
}
]
Expand Down
2 changes: 0 additions & 2 deletions internal/endtoend/testdata/array_in/pgx/v4/query.sql
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
CREATE TABLE bar (id serial not null);

-- name: In :many
SELECT *
FROM bar
Expand Down
2 changes: 2 additions & 0 deletions internal/endtoend/testdata/array_in/pgx/v4/schema.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
CREATE TABLE bar (id serial not null);

2 changes: 1 addition & 1 deletion internal/endtoend/testdata/array_in/pgx/v4/sqlc.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"engine": "postgresql",
"sql_package": "pgx/v4",
"name": "querytest",
"schema": "query.sql",
"schema": "schema.sql",
"queries": "query.sql"
}
]
Expand Down
2 changes: 0 additions & 2 deletions internal/endtoend/testdata/array_in/pgx/v5/query.sql
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
CREATE TABLE bar (id serial not null);

-- name: In :many
SELECT *
FROM bar
Expand Down
2 changes: 2 additions & 0 deletions internal/endtoend/testdata/array_in/pgx/v5/schema.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
CREATE TABLE bar (id serial not null);

2 changes: 1 addition & 1 deletion internal/endtoend/testdata/array_in/pgx/v5/sqlc.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"engine": "postgresql",
"sql_package": "pgx/v5",
"name": "querytest",
"schema": "query.sql",
"schema": "schema.sql",
"queries": "query.sql"
}
]
Expand Down
2 changes: 0 additions & 2 deletions internal/endtoend/testdata/array_in/stdlib/query.sql
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
CREATE TABLE bar (id serial not null);

-- name: In :many
SELECT *
FROM bar
Expand Down
2 changes: 2 additions & 0 deletions internal/endtoend/testdata/array_in/stdlib/schema.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
CREATE TABLE bar (id serial not null);

2 changes: 1 addition & 1 deletion internal/endtoend/testdata/array_in/stdlib/sqlc.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
{
"path": "go",
"name": "querytest",
"schema": "query.sql",
"schema": "schema.sql",
"queries": "query.sql"
}
]
Expand Down
2 changes: 0 additions & 2 deletions internal/endtoend/testdata/array_text/pgx/v4/query.sql
Original file line number Diff line number Diff line change
@@ -1,4 +1,2 @@
CREATE TABLE bar (tags text[] not null);

-- name: TextArray :many
SELECT * FROM bar;
2 changes: 2 additions & 0 deletions internal/endtoend/testdata/array_text/pgx/v4/schema.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
CREATE TABLE bar (tags text[] not null);

2 changes: 1 addition & 1 deletion internal/endtoend/testdata/array_text/pgx/v4/sqlc.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"engine": "postgresql",
"sql_package": "pgx/v4",
"name": "querytest",
"schema": "query.sql",
"schema": "schema.sql",
"queries": "query.sql"
}
]
Expand Down
2 changes: 0 additions & 2 deletions internal/endtoend/testdata/array_text/pgx/v5/query.sql
Original file line number Diff line number Diff line change
@@ -1,4 +1,2 @@
CREATE TABLE bar (tags text[] not null);

-- name: TextArray :many
SELECT * FROM bar;
2 changes: 2 additions & 0 deletions internal/endtoend/testdata/array_text/pgx/v5/schema.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
CREATE TABLE bar (tags text[] not null);

2 changes: 1 addition & 1 deletion internal/endtoend/testdata/array_text/pgx/v5/sqlc.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"engine": "postgresql",
"sql_package": "pgx/v5",
"name": "querytest",
"schema": "query.sql",
"schema": "schema.sql",
"queries": "query.sql"
}
]
Expand Down
2 changes: 0 additions & 2 deletions internal/endtoend/testdata/array_text/stdlib/query.sql
Original file line number Diff line number Diff line change
@@ -1,4 +1,2 @@
CREATE TABLE bar (tags text[] not null);

-- name: TextArray :many
SELECT * FROM bar;
2 changes: 2 additions & 0 deletions internal/endtoend/testdata/array_text/stdlib/schema.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
CREATE TABLE bar (tags text[] not null);

2 changes: 1 addition & 1 deletion internal/endtoend/testdata/array_text/stdlib/sqlc.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
{
"path": "go",
"name": "querytest",
"schema": "query.sql",
"schema": "schema.sql",
"queries": "query.sql"
}
]
Expand Down
3 changes: 0 additions & 3 deletions internal/endtoend/testdata/array_text_join/pgx/v4/query.sql
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
CREATE TABLE foo (id text not null, bar text not null);
CREATE TABLE bar (id text not null, info text[] not null);

-- name: JoinTextArray :many
SELECT bar.info
FROM foo
Expand Down
3 changes: 3 additions & 0 deletions internal/endtoend/testdata/array_text_join/pgx/v4/schema.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
CREATE TABLE foo (id text not null, bar text not null);
CREATE TABLE bar (id text not null, info text[] not null);

Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"engine": "postgresql",
"sql_package": "pgx/v4",
"name": "querytest",
"schema": "query.sql",
"schema": "schema.sql",
"queries": "query.sql"
}
]
Expand Down
3 changes: 0 additions & 3 deletions internal/endtoend/testdata/array_text_join/pgx/v5/query.sql
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
CREATE TABLE foo (id text not null, bar text not null);
CREATE TABLE bar (id text not null, info text[] not null);

-- name: JoinTextArray :many
SELECT bar.info
FROM foo
Expand Down
3 changes: 3 additions & 0 deletions internal/endtoend/testdata/array_text_join/pgx/v5/schema.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
CREATE TABLE foo (id text not null, bar text not null);
CREATE TABLE bar (id text not null, info text[] not null);

Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"engine": "postgresql",
"sql_package": "pgx/v5",
"name": "querytest",
"schema": "query.sql",
"schema": "schema.sql",
"queries": "query.sql"
}
]
Expand Down
3 changes: 0 additions & 3 deletions internal/endtoend/testdata/array_text_join/stdlib/query.sql
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
CREATE TABLE foo (id text not null, bar text not null);
CREATE TABLE bar (id text not null, info text[] not null);

-- name: JoinTextArray :many
SELECT bar.info
FROM foo
Expand Down
3 changes: 3 additions & 0 deletions internal/endtoend/testdata/array_text_join/stdlib/schema.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
CREATE TABLE foo (id text not null, bar text not null);
CREATE TABLE bar (id text not null, info text[] not null);

Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
{
"path": "go",
"name": "querytest",
"schema": "query.sql",
"schema": "schema.sql",
"queries": "query.sql"
}
]
Expand Down
3 changes: 0 additions & 3 deletions internal/endtoend/testdata/batch/postgresql/pgx/v4/query.sql
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
CREATE SCHEMA myschema;
CREATE TABLE myschema.foo (a text, b integer);

-- name: InsertValues :batchone
INSERT INTO myschema.foo (a, b)
VALUES ($1, $2)
Expand Down
3 changes: 3 additions & 0 deletions internal/endtoend/testdata/batch/postgresql/pgx/v4/schema.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
CREATE SCHEMA myschema;
CREATE TABLE myschema.foo (a text, b integer);

Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"engine": "postgresql",
"sql_package": "pgx/v4",
"name": "querytest",
"schema": "query.sql",
"schema": "schema.sql",
"queries": "query.sql"
}
]
Expand Down
3 changes: 0 additions & 3 deletions internal/endtoend/testdata/batch/postgresql/pgx/v5/query.sql
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
CREATE SCHEMA myschema;
CREATE TABLE myschema.foo (a text, b integer);

-- name: InsertValues :batchone
INSERT INTO myschema.foo (a, b)
VALUES ($1, $2)
Expand Down
3 changes: 3 additions & 0 deletions internal/endtoend/testdata/batch/postgresql/pgx/v5/schema.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
CREATE SCHEMA myschema;
CREATE TABLE myschema.foo (a text, b integer);

Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"engine": "postgresql",
"sql_package": "pgx/v5",
"name": "querytest",
"schema": "query.sql",
"schema": "schema.sql",
"queries": "query.sql"
}
]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
CREATE SCHEMA myschema;
CREATE TABLE myschema.foo (a text, b integer);

-- name: InsertValues :batchone
INSERT INTO myschema.foo (a, b)
VALUES ($1, $2)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
CREATE SCHEMA myschema;
CREATE TABLE myschema.foo (a text, b integer);

Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"engine": "postgresql",
"sql_package": "pgx/v4",
"name": "querytest",
"schema": "query.sql",
"schema": "schema.sql",
"queries": "query.sql"
}
]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
CREATE SCHEMA myschema;
CREATE TABLE myschema.foo (a text, b integer);

-- name: InsertValues :batchone
INSERT INTO myschema.foo (a, b)
VALUES ($1, $2)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
CREATE SCHEMA myschema;
CREATE TABLE myschema.foo (a text, b integer);

Loading
Loading