Skip to content

Commit

Permalink
Merge pull request #102 from kaaveland/draw-random-example-on-web
Browse files Browse the repository at this point in the history
Bake example scripts into `eugene` executable and improve demo
  • Loading branch information
kaaveland authored Jun 15, 2024
2 parents 69d0b0e + 040d6d1 commit 59c1231
Show file tree
Hide file tree
Showing 151 changed files with 652 additions and 429 deletions.
1 change: 1 addition & 0 deletions .github/workflows/run_tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ on:

env:
CARGO_TERM_COLOR: always
RUST_BACKTRACE: "1"
jobs:
run_tests_ubuntu:
runs-on: ubuntu-latest
Expand Down
9 changes: 9 additions & 0 deletions eugene-web/src/webapp.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
use crate::webapp;
use axum::routing::{get, post};
use axum::Router;
use eugene::hint_data::ALL;

pub mod error;
pub mod index;
Expand All @@ -9,10 +11,17 @@ pub mod lint_raw;
pub mod requestlog;
pub mod templates;

async fn random_sql() -> Result<impl axum::response::IntoResponse, webapp::error::WebAppError> {
let n: usize = rand::random();
let choice = n % ALL.len();
Ok(ALL[choice].bad_example)
}

pub fn routes() -> Router {
Router::new()
.route("/", get(index::render_index))
.route("/lint.html", post(lint_html::lint_html))
.route("/lint.json", post(lint_json::json_lint_handler))
.route("/lint.raw", post(lint_raw::raw_lint_handler))
.route("/random.sql", get(random_sql))
}
7 changes: 0 additions & 7 deletions eugene/docs/src/hints/E1/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,46 +14,39 @@

```sql
-- 1.sql

create table authors(
id integer generated always as identity
primary key,
name text
);

-- 2.sql

set local lock_timeout = '2s';
alter table authors
add constraint name_not_null
check (name is not null);

```

## Safer migration

```sql
-- 1.sql

create table authors(
id integer generated always as identity
primary key,
name text
);

-- 2.sql

set local lock_timeout = '2s';
alter table authors
add constraint name_not_null
check (name is not null) not valid;

-- 3.sql

set local lock_timeout = '2s';
alter table authors
validate constraint name_not_null;

```

## Eugene report examples
Expand Down
3 changes: 3 additions & 0 deletions eugene/docs/src/hints/E1/safer_lint.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ The migration script passed all the checks ✅
### Statement number 1
#### SQL
```sql
-- 1.sql
create table authors(
id integer generated always as identity
primary key,
Expand All @@ -28,6 +29,7 @@ The migration script passed all the checks ✅
### Statement number 1
#### SQL
```sql
-- 2.sql
set local lock_timeout = '2s'
```
No checks matched for this statement. ✅
Expand All @@ -51,6 +53,7 @@ The migration script passed all the checks ✅
### Statement number 1
#### SQL
```sql
-- 3.sql
set local lock_timeout = '2s'
```
No checks matched for this statement. ✅
Expand Down
3 changes: 3 additions & 0 deletions eugene/docs/src/hints/E1/safer_trace.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#### SQL

```sql
-- 1.sql
create table authors(
id integer generated always as identity
primary key,
Expand All @@ -33,6 +34,7 @@ No new locks taken by this statement.
#### SQL

```sql
-- 2.sql
set local lock_timeout = '2s'
```

Expand Down Expand Up @@ -77,6 +79,7 @@ No locks held at the start of this statement.
#### SQL

```sql
-- 3.sql
set local lock_timeout = '2s'
```

Expand Down
2 changes: 2 additions & 0 deletions eugene/docs/src/hints/E1/unsafe_lint.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ The migration script passed all the checks ✅
### Statement number 1
#### SQL
```sql
-- 1.sql
create table authors(
id integer generated always as identity
primary key,
Expand All @@ -28,6 +29,7 @@ The migration script did not pass all the checks ❌
### Statement number 1
#### SQL
```sql
-- 2.sql
set local lock_timeout = '2s'
```
No checks matched for this statement. ✅
Expand Down
2 changes: 2 additions & 0 deletions eugene/docs/src/hints/E1/unsafe_trace.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#### SQL

```sql
-- 1.sql
create table authors(
id integer generated always as identity
primary key,
Expand All @@ -33,6 +34,7 @@ No new locks taken by this statement.
#### SQL

```sql
-- 2.sql
set local lock_timeout = '2s'
```

Expand Down
7 changes: 0 additions & 7 deletions eugene/docs/src/hints/E10/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@

```sql
-- 1.sql

create table prices (
id integer generated always as identity
primary key,
Expand All @@ -28,22 +27,19 @@ create table authors (
);

-- 2.sql

set local lock_timeout = '2s';
alter table authors add column meta jsonb;

-- eugene: ignore E5, E4
-- causes table rewrite, but this example isnt't about that
alter table prices
alter price set data type bigint;

```

## Safer migration

```sql
-- 1.sql

create table prices (
id integer generated always as identity
primary key,
Expand All @@ -57,19 +53,16 @@ create table authors (
);

-- 2.sql

set local lock_timeout = '2s';
alter table authors
add column meta jsonb;

-- 3.sql

set local lock_timeout = '2s';
-- eugene: ignore E5, E4
-- causes table rewrite, but this example isnt't about that
alter table prices
alter price set data type bigint;

```

## Eugene report examples
Expand Down
3 changes: 3 additions & 0 deletions eugene/docs/src/hints/E10/safer_lint.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ The migration script passed all the checks ✅
### Statement number 1
#### SQL
```sql
-- 1.sql
create table prices (
id integer generated always as identity
primary key,
Expand Down Expand Up @@ -38,6 +39,7 @@ The migration script passed all the checks ✅
### Statement number 1
#### SQL
```sql
-- 2.sql
set local lock_timeout = '2s'
```
No checks matched for this statement. ✅
Expand All @@ -60,6 +62,7 @@ The migration script passed all the checks ✅
### Statement number 1
#### SQL
```sql
-- 3.sql
set local lock_timeout = '2s'
```
No checks matched for this statement. ✅
Expand Down
3 changes: 3 additions & 0 deletions eugene/docs/src/hints/E10/safer_trace.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#### SQL

```sql
-- 1.sql
create table prices (
id integer generated always as identity
primary key,
Expand Down Expand Up @@ -55,6 +56,7 @@ No new locks taken by this statement.
#### SQL

```sql
-- 2.sql
set local lock_timeout = '2s'
```

Expand Down Expand Up @@ -98,6 +100,7 @@ No locks held at the start of this statement.
#### SQL

```sql
-- 3.sql
set local lock_timeout = '2s'
```

Expand Down
2 changes: 2 additions & 0 deletions eugene/docs/src/hints/E10/unsafe_lint.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ The migration script passed all the checks ✅
### Statement number 1
#### SQL
```sql
-- 1.sql
create table prices (
id integer generated always as identity
primary key,
Expand Down Expand Up @@ -38,6 +39,7 @@ The migration script passed all the checks ✅
### Statement number 1
#### SQL
```sql
-- 2.sql
set local lock_timeout = '2s'
```
No checks matched for this statement. ✅
Expand Down
2 changes: 2 additions & 0 deletions eugene/docs/src/hints/E10/unsafe_trace.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#### SQL

```sql
-- 1.sql
create table prices (
id integer generated always as identity
primary key,
Expand Down Expand Up @@ -55,6 +56,7 @@ No new locks taken by this statement.
#### SQL

```sql
-- 2.sql
set local lock_timeout = '2s'
```

Expand Down
3 changes: 0 additions & 3 deletions eugene/docs/src/hints/E11/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,14 @@

```sql
-- 1.sql

create table prices (
price int not null
);

-- 2.sql

set local lock_timeout = '2s';
alter table prices
add column id serial;

```

## Safer migration
Expand Down
2 changes: 2 additions & 0 deletions eugene/docs/src/hints/E11/unsafe_lint.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ The migration script passed all the checks ✅
### Statement number 1
#### SQL
```sql
-- 1.sql
create table prices (
price int not null
)
Expand All @@ -26,6 +27,7 @@ The migration script did not pass all the checks ❌
### Statement number 1
#### SQL
```sql
-- 2.sql
set local lock_timeout = '2s'
```
No checks matched for this statement. ✅
Expand Down
2 changes: 2 additions & 0 deletions eugene/docs/src/hints/E11/unsafe_trace.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#### SQL

```sql
-- 1.sql
create table prices (
price int not null
)
Expand All @@ -31,6 +32,7 @@ No new locks taken by this statement.
#### SQL

```sql
-- 2.sql
set local lock_timeout = '2s'
```

Expand Down
8 changes: 0 additions & 8 deletions eugene/docs/src/hints/E2/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,53 +14,45 @@

```sql
-- 1.sql

create table authors(
id integer generated always as identity
primary key,
name text
);

-- 2.sql

set local lock_timeout = '2s';
alter table authors
alter column name set not null;

```

## Safer migration

```sql
-- 1.sql

create table authors(
id integer generated always as identity
primary key,
name text
);

-- 2.sql

set local lock_timeout = '2s';
alter table authors
add constraint check_name_not_null
check (name is not null) not valid;

-- 3.sql

set local lock_timeout = '2s';
alter table authors
validate constraint check_name_not_null;

-- 4.sql

set local lock_timeout = '2s';
-- eugene trace knows name has a valid not null check, but eugene lint doesn't
-- eugene: ignore E2
alter table authors
alter name set not null;

```

## Eugene report examples
Expand Down
Loading

0 comments on commit 59c1231

Please sign in to comment.