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

Add support for sqlite3 to dbfixtures executor #613

Merged
merged 3 commits into from
Jan 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
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
);