Skip to content

Commit

Permalink
feat(dbfixtures): add support for sqlite3
Browse files Browse the repository at this point in the history
Add support for sqlite3 to dbfixtures executor (#613)

Signed-off-by: Elias Tandel <elias.tandel@90poe.io>
  • Loading branch information
etandel authored Jan 4, 2023
1 parent 7f75ae8 commit 80cff7a
Show file tree
Hide file tree
Showing 5 changed files with 100 additions and 2 deletions.
35 changes: 34 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -930,11 +930,44 @@ To display properly the venom output, you probably will have to export the envir

[How to write your own executor?](https://github.com/ovh/venom/tree/master/executors#venom-executor)

How to compile?
## How to compile?
```bash
$ make build
```

## How to test?

### Unit tests:

```bash
make test
```

### Integration tests:

Prepare the stack:

```bash
make build OS=linux ARCH=amd64
cp dist/venom.linux-amd64 tests/venom
cd tests
make start-test-stack # (wait a few seconds)
make build-test-binary-docker
```

Run integration tests:

```bash
make run-test
```

Cleanup:

```bash
make clean
make stop-test-stack
```

# Contributing

<a href="https://gitpod.io/#https://github.com/ovh/venom"><img src="https://img.shields.io/badge/Contribute%20with-Gitpod-908a85?logo=gitpod" alt="Contribute with Gitpod"/></a>
Expand Down
2 changes: 1 addition & 1 deletion executors/dbfixtures/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ Please read its documentation for further details about the parameters of this e
In your yaml file, you declare tour step like this

```yaml
- database mandatory [mysql/postgres]
- database mandatory [mysql/postgres/sqlite3]
- dsn mandatory
- schemas optional
- migrations optional
Expand Down
3 changes: 3 additions & 0 deletions executors/dbfixtures/dbfixtures.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import (
// SQL drivers.
_ "github.com/go-sql-driver/mysql"
_ "github.com/lib/pq"
_ "github.com/mattn/go-sqlite3"

"github.com/ovh/venom"
)
Expand Down Expand Up @@ -182,6 +183,8 @@ func getDialect(name string, skipResetSequences bool) func(*fixtures.Loader) err
}
case "mysql":
return fixtures.Dialect("mysql")
case "sqlite3":
return fixtures.Dialect("sqlite3")
}
return nil
}
17 changes: 17 additions & 0 deletions tests/db_fixtures.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,20 @@ testcases:
dsn: "user=venom password=venom dbname=venom host={{.pgHost}} port={{.pgPort}} sslmode=disable"
migrations_path: dbfixtures/testdata/migrations
folder: dbfixtures/testdata/fixtures

- name: load-fixtures-into-sqlite3-database
steps:
- type: dbfixtures
database: sqlite3
dsn: ":memory:"
schemas:
- dbfixtures/testdata/schemas/sqlite3.sql
folder: dbfixtures/testdata/fixtures

- name: initialize-sqlite3-database-with-migrations
steps:
- type: dbfixtures
database: sqlite3
dsn: "memory"
migrations: dbfixtures/testdata/migrations
folder: dbfixtures/testdata/fixtures
45 changes: 45 additions & 0 deletions tests/dbfixtures/testdata/schemas/sqlite3.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
DROP TABLE IF EXISTS comments;
DROP TABLE IF EXISTS posts_tags;
DROP TABLE IF EXISTS posts;
DROP TABLE IF EXISTS tags;
DROP TABLE IF EXISTS users;

CREATE TABLE posts (
id SERIAL PRIMARY KEY
,title VARCHAR NOT NULL
,content TEXT NOT NULL
,created_at TIMESTAMP NOT NULL
,updated_at TIMESTAMP NOT NULL
);

CREATE TABLE tags (
id SERIAL PRIMARY KEY
,name VARCHAR NOT NULL
,created_at TIMESTAMP NOT NULL
,updated_at TIMESTAMP NOT NULL
);

CREATE TABLE posts_tags (
post_id INTEGER NOT NULL
,tag_id INTEGER NOT NULL
,PRIMARY KEY (post_id, tag_id)
,FOREIGN KEY (post_id) REFERENCES posts (id)
,FOREIGN KEY (tag_id) REFERENCES tags (id)
);

CREATE TABLE comments (
id SERIAL PRIMARY KEY NOT NULL
,post_id INTEGER NOT NULL
,author_name VARCHAR NOT NULL
,author_email VARCHAR NOT NULL
,content TEXT NOT NULL
,created_at TIMESTAMP NOT NULL
,updated_at TIMESTAMP NOT NULL
,FOREIGN KEY (post_id) REFERENCES posts (id)
);

CREATE TABLE users (
id SERIAL PRIMARY KEY NOT NULL
,attributes VARCHAR NOT NULL
);

0 comments on commit 80cff7a

Please sign in to comment.