Skip to content

Commit c7c00fc

Browse files
committed
Cleaning up.
1 parent 3a14336 commit c7c00fc

9 files changed

Lines changed: 12 additions & 294 deletions

File tree

.github/workflows/go.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ jobs:
1313
runs-on: ubuntu-latest
1414
strategy:
1515
matrix:
16-
driver: ['mssql','pgsql']
16+
driver: ['mssql']
1717
steps:
1818
- uses: actions/checkout@v5
1919

docker-compose.mssql.yml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,19 @@
11
services:
22
mssql:
3-
image: mcr.microsoft.com/mssql/server:latest
3+
image: mcr.microsoft.com/mssql/server:2022-CU18-ubuntu-22.04
44
networks:
55
- mssql
66
environment:
77
ACCEPT_EULA: "Y"
88
SA_PASSWORD: VippsPw1
99
healthcheck:
10-
test: ["CMD", "/opt/mssql-tools18/bin/sqlcmd", "-C", "-Usa", "-PVippsPw1", "-Q", "select 1"]
10+
test: ["CMD", "/opt/mssql-tools18/bin/sqlcmd", "-C", "-Usa", "-PVippsPw1", "-Q", "'select 1'"]
1111
interval: 1s
1212
retries: 20
1313
test:
1414
build:
15+
context: .
16+
no_cache: true
1517
dockerfile: dockerfile.test
1618
networks:
1719
- mssql

migrations/0001.sqlcode.pgsql

Lines changed: 0 additions & 229 deletions
This file was deleted.

sqlcode.yaml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
databases:
22
mssql:
33
connection: sqlserver://mssql:1433?database=foo&user id=foouser&password=FooPasswd1
4-
pgsql:
5-
connection: postgresql://sa:VippsPw1@postgres:5432/master?sslmode=disable
6-
4+
75
# One option is to list other paths to include ('dependencies') here.
86

97
# Commands to set up for testing with credentials above:

sqlparser/parser.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ package sqlparser
66

77
import (
88
"crypto/sha256"
9-
"errors"
109
"fmt"
1110
"io/fs"
1211
"path/filepath"
@@ -84,8 +83,8 @@ func ParseFilesystems(fslst []fs.FS, includeTags []string) (filenames []string,
8483
hash := sha256.Sum256(buf)
8584
existingPathDesc, hashExists := hashes[hash]
8685
if hashExists {
87-
return errors.New(fmt.Sprintf("file %s has exact same contents as %s (possibly in different filesystems)",
88-
pathDesc, existingPathDesc))
86+
return fmt.Errorf("file %s has exact same contents as %s (possibly in different filesystems)",
87+
pathDesc, existingPathDesc)
8988
}
9089
hashes[hash] = pathDesc
9190

@@ -98,6 +97,9 @@ func ParseFilesystems(fslst []fs.FS, includeTags []string) (filenames []string,
9897
// only include if include tags match
9998
if matchesIncludeTags(fdoc.PragmaIncludeIf(), includeTags) {
10099
filenames = append(filenames, pathDesc)
100+
if result == nil {
101+
result = &mssql.TSqlDocument{}
102+
}
101103
result.Include(fdoc)
102104
}
103105
}

sqltest/fixture.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ func NewFixture() *Fixture {
8787
// 8: Trace SQL statements
8888
// 16: Log statement parameters
8989
// 32: Log transaction begin/end
90-
dsn = dsn + "&log=63"
90+
dsn = dsn + "&log=2"
9191
mssql.SetLogger(StdoutLogger{})
9292
fixture.Driver = SqlDriverMssql
9393
}

sqltest/sql.go

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,7 @@ import (
99
//go:embed *.sql
1010
var sqlfs embed.FS
1111

12-
//go:embed *.pgsql
13-
var pgsqlfx embed.FS
14-
1512
var SQL = sqlcode.MustInclude(
1613
sqlcode.Options{},
1714
sqlfs,
18-
pgsqlfx,
1915
)

sqltest/sqlcode_test.go

Lines changed: 0 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ package sqltest
22

33
import (
44
"context"
5-
"fmt"
65
"testing"
76

87
"github.com/stretchr/testify/assert"
@@ -18,13 +17,6 @@ func Test_Patch(t *testing.T) {
1817
fixture.RunMigrationFile("../migrations/0001.sqlcode.sql")
1918
}
2019

21-
if fixture.IsPostgresql() {
22-
fixture.RunMigrationFile("../migrations/0001.sqlcode.pgsql")
23-
_, err := fixture.DB.Exec(
24-
fmt.Sprintf(`grant create on database "%s" to "sqlcode-definer-role"`, fixture.DBName))
25-
require.NoError(t, err)
26-
}
27-
2820
require.NoError(t, SQL.EnsureUploaded(ctx, fixture.DB))
2921

3022
fixture.RunIfMssql(t, "returns 1 affected row", func(t *testing.T) {
@@ -36,18 +28,6 @@ func Test_Patch(t *testing.T) {
3628
require.NoError(t, err)
3729
assert.Equal(t, int64(1), rowsAffected)
3830
})
39-
40-
// TODO: instrument a test table to perform an update operation
41-
fixture.RunIfPostgres(t, "returns 0 affected rows", func(t *testing.T) {
42-
patched := SQL.CodePatch(fixture.DB, `call [code].Test()`)
43-
res, err := fixture.DB.ExecContext(ctx, patched)
44-
require.NoError(t, err)
45-
46-
// postgresql perform does not result with affected rows
47-
rowsAffected, err := res.RowsAffected()
48-
require.NoError(t, err)
49-
assert.Equal(t, int64(0), rowsAffected)
50-
})
5131
}
5232

5333
func Test_EnsureUploaded(t *testing.T) {
@@ -63,19 +43,6 @@ func Test_EnsureUploaded(t *testing.T) {
6343
require.Len(t, schemas, 1)
6444

6545
})
66-
67-
f.RunIfPostgres(t, "uploads schema", func(t *testing.T) {
68-
f.RunMigrationFile("../migrations/0001.sqlcode.pgsql")
69-
70-
_, err := f.DB.Exec(
71-
fmt.Sprintf(`grant create on database "%s" to "sqlcode-definer-role"`, f.DBName))
72-
require.NoError(t, err)
73-
74-
require.NoError(t, SQL.EnsureUploaded(ctx, f.DB))
75-
schemas, err := SQL.ListUploaded(ctx, f.DB)
76-
require.NoError(t, err)
77-
require.Len(t, schemas, 1)
78-
})
7946
}
8047

8148
func Test_DropAndUpload(t *testing.T) {
@@ -88,15 +55,4 @@ func Test_DropAndUpload(t *testing.T) {
8855
require.NoError(t, SQL.EnsureUploaded(ctx, f.DB))
8956
require.NoError(t, SQL.DropAndUpload(ctx, f.DB))
9057
})
91-
92-
f.RunIfPostgres(t, "drop and upload", func(t *testing.T) {
93-
f.RunMigrationFile("../migrations/0001.sqlcode.pgsql")
94-
95-
_, err := f.DB.Exec(
96-
fmt.Sprintf(`grant create on database "%s" to "sqlcode-definer-role"`, f.DBName))
97-
require.NoError(t, err)
98-
99-
require.NoError(t, SQL.EnsureUploaded(ctx, f.DB))
100-
require.NoError(t, SQL.DropAndUpload(ctx, f.DB))
101-
})
10258
}

0 commit comments

Comments
 (0)