Skip to content

Commit

Permalink
Merge branch 'main' into nix-pkg
Browse files Browse the repository at this point in the history
  • Loading branch information
emilpriver authored May 6, 2024
2 parents fb79611 + 688bb3c commit 9c70a8d
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 42 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ jobs:
- name: Generate test migrations
run: bash scripts/test-migrations.sh
- name: Test action
uses: ./action.yaml
uses: ./
with:
migrations_folder: "./migrations"
wait_timeout: "30"
Expand Down
48 changes: 25 additions & 23 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,10 @@ async-trait = "0.1.80"
chrono = { version = "0.4.31", features = ["serde"] }
clap = { version = "4.5.2", features = ["env", "string", "derive", "cargo"] }
futures = "0.3.30"
serde = { version = "1.0.197", features = ["derive"] }
serde = { version = "1.0.200", features = ["derive"] }
log = { version = "0.4.21", features = ["max_level_debug", "serde"] }
serde_json = "1.0.108"
serial_test = "3.0.0"
serial_test = "3.1.1"
simplelog = "0.12.2"
tokio = { version = "1.36.0", features = ["full"] }
sqlx = { version = "0.7.3", features = ["runtime-tokio", "chrono", "postgres", "mysql", "time"] }
Expand Down
1 change: 1 addition & 0 deletions Dockerfile.slim
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ FROM gcr.io/distroless/cc-debian12
COPY --from=builder /usr/src/app/geni /usr/src/app/geni

ENV DATABASE_MIGRATIONS_FOLDER="/migrations"
ENV DATABASE_NO_DUMP_SCHEMA="true"

LABEL org.opencontainers.image.description "Geni: Standalone database migration tool which works for Postgres, MariaDB, MySQL, Sqlite and LibSQL(Turso)."

Expand Down
39 changes: 23 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,14 @@ The application is developed using the Rust programming language and relies on t

### Github

```
```bash
$ sudo curl -fsSL -o /usr/local/bin/geni https://github.com/emilpriver/geni/releases/latest/download/geni-linux-amd64
$ sudo chmod +x /usr/local/bin/geni
```

### Homebrew

```
```bash
brew install emilpriver/geni/geni
```

Expand All @@ -55,33 +55,40 @@ TBA

### PKGX
Run using PKGX
```
```bash
pkgx geni up
```

### Cargo

```
```bash
cargo install geni
```

### Docker

Docker images are published to GitHub Container Registry ([ghcr.io/emilpriver/geni](https://ghcr.io/emilpriver/geni)).

```
```bash
$ docker run --rm -it --network=host ghcr.io/emilpriver/geni:latest --help
```
there is also a slim docker image that don't have each database respective libraries(such as pg_dump).

If you wish to create or apply migrations, you will need to use Docker's [bind mount](https://docs.docker.com/storage/bind-mounts/) feature to make your local working directory (`pwd`) available inside the geni container:
Note: *This image won't try to dump the database*

```bash
$ docker run --rm -it --network=host ghcr.io/emilpriver/geni:latest-slim --help
```

If you wish to create or apply migrations, you will need to use Docker's [bind mount](https://docs.docker.com/storage/bind-mounts/) feature to make your local working directory (`pwd`) available inside the geni container:

```bash
$ docker run --rm -it --network=host -v "$(pwd)/migrations:/migrations" ghcr.io/emilpriver/geni:latest new create_users_table`
```

### Commands

```rust
```bash
geni new # Generate a new migrations file
geni up # Run any pending migration
geni down # Rollback migrations, use --amount to speify how many migrations(default 1)
Expand Down Expand Up @@ -121,7 +128,7 @@ geni help # Print help message

Running

```rust
```bash
DATABASE_URL="x" geni new hello_world
```

Expand All @@ -131,15 +138,15 @@ Example:

If I want to create table named `Persons` should I add this to `.up.sql`

```rust
```sql
CREATE TABLE Persons (
PersonID int
)
```

And the rollback migration should then be

```rust
```sql
DROP TABLE Persons;
```

Expand All @@ -166,33 +173,33 @@ CREATE TABLE table_2 (
Running migration can be done using
```rust
```bash
geni up
```
### Rollback migrations
Rollbacking last added migrations can be done using
```rust
```bash
geni down
```
and If you want to rollback more then 1 can you add `-a` to the cli to specify how many
```rust
```bash
geni down -a 3
```
### Running from CLI
```rust
```bash
DATABASE_URL="postgres://[email protected]:5432/app?sslmode=disable" geni up
```
### Github Workflow
```
```yaml
- uses: emilpriver/geni@main
with:
migrations_folder: "./migrations"
Expand All @@ -217,7 +224,7 @@ DATABASE_URL="postgres://[email protected]:5432/app?sslmode=disable" geni up
In a CI/CD should the database_url come from a security store and be appended to the environment as the `DATABASE_URL`. If the `DATABASE_URL` is provided as a environment variable is the only command you need to run
```rust
```bash
geni up
```
Expand Down

0 comments on commit 9c70a8d

Please sign in to comment.