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

Update spec tests and add ghaction #474

Merged
merged 39 commits into from May 3, 2023

Conversation

kalinon
Copy link
Contributor

@kalinon kalinon commented Apr 28, 2023

  • update docker to use crystal 1.8 and added github action
  • fix workflow if statements
  • split workflow into separate jobs for each database
  • workflow: fix missing envs
  • workflow: add psql db var
  • attempt to use workflow services
  • split tests by database to speed things up

Sqlite and MySQL specs are passing. PSQL still is having issues.

PSQL: 284 examples, 1 failures, 3 errors, 0 pending

kalinon and others added 30 commits August 28, 2021 10:25
If a column is named `created_at` or `updated_at` is not a type `Time?`, then the following occurs:

```There was a problem expanding macro 'macro_4801706624'

Code in lib/granite/src/granite/transactions.cr:82:5

 82 | {% if @type.instance_vars.select { |ivar| ivar.annotation(Granite::Column) }.map(&.name.stringify).includes? "created_at" %}
      ^
Called macro defined in lib/granite/src/granite/transactions.cr:82:5

 82 | {% if @type.instance_vars.select { |ivar| ivar.annotation(Granite::Column) }.map(&.name.stringify).includes? "created_at" %}

Which expanded to:

 > 1 |
 > 2 |       if mode == :create
 > 3 |         @created_at = time.at_beginning_of_second
                                  ^---------------------
```

this simply adds a type check.
* Quote fields in PG query assembler

* Created converter for PG Enums that are returned as bytes

* Quote table names in adapter methods only if not already quoted

* Check if table/column string has already been quoted

* Quote foreign key

* Quote fields in query assemblers

* added some docs

* Created converter for Postgres enum arrays

* Incorrect variable name

* Added target key to association collection for many relations type

* Added truncate function for postgres adapter

* Removed unrequired parameter

* Rogue value in log for truncate

* Added truncate method for models

* Add JsonString converter

* Must use chars to check string index equality

* add note for custom select macro

* removed some other commits

* removed changes from other pr

* removed work from other pr

* removed work from other pr

* removed commits from other pr

---------

Co-authored-by: ionica21 <ionicat@windowslive.com>
Co-authored-by: Joakim Repomaa <mail@jreinert.com>
…ork#454)

If a column is named `created_at` or `updated_at` is not a type `Time?`, then the following occurs:

```There was a problem expanding macro 'macro_4801706624'

Code in lib/granite/src/granite/transactions.cr:82:5

 82 | {% if @type.instance_vars.select { |ivar| ivar.annotation(Granite::Column) }.map(&.name.stringify).includes? "created_at" %}
      ^
Called macro defined in lib/granite/src/granite/transactions.cr:82:5

 82 | {% if @type.instance_vars.select { |ivar| ivar.annotation(Granite::Column) }.map(&.name.stringify).includes? "created_at" %}

Which expanded to:

 > 1 |
 > 2 |       if mode == :create
 > 3 |         @created_at = time.at_beginning_of_second
                                  ^---------------------
```

this simply adds a type check.
* update docker to use crystal 1.8 and added github action
* fix workflow if statements
* split workflow into separate jobs for each database
* workflow: fix missing envs
* workflow: add psql db var
* attempt to use workflow services
* split tests by database to speed things up
.github/workflows/spec.yml Outdated Show resolved Hide resolved
@@ -2,7 +2,7 @@ PG_DATABASE_URL=postgres://granite:password@localhost:5432/granite_db
MYSQL_DATABASE_URL=mysql://granite:password@localhost:3306/granite_db
SQLITE_DATABASE_URL=sqlite3:./granite.db
CURRENT_ADAPTER=pg
PG_VERSION=10.4
PG_VERSION=15.2
MYSQL_VERSION=5.7
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably should change this to use v8 instead of v5.7 since 5.7 is EOL

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

agreed, i did run it against 8, but there's a bug/issue with connecting to 8 with the adapter.
crystal-lang/crystal-mysql#62

I suggest we handle moving to 8 for testing in a separate issue, as it will take me a bit to work around it.

@@ -48,13 +48,13 @@ require "../spec_helper"
end

it "property defines IN query" do
sql = "SELECT #{query_fields} FROM table WHERE date_completed IS NULL AND status IN ('outstanding','in_progress') ORDER BY id DESC"
sql = "SELECT #{query_fields} FROM table WHERE date_completed IS NULL AND status IN (?,?) ORDER BY id DESC"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice catch there!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, this was an change i made to the underlying lib. Previously granite was attempting to escape the string itself by wrapping it in single quotes, but it broke with strings that contained them such as "joe's burger". Now strings are passed down to the underlying adapter for variable substitution.

Only Bool and Number are substituted by granite.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can't remember why we were doing that at all, but maybe there's a reason. I think ideally we should avoid doing any substitution in queries ourselves, since the database is better equipped to do that for us safely.

spec/spec_helper.cr Show resolved Hide resolved
spec/spec_helper.cr Show resolved Hide resolved
Copy link
Member

@robacarp robacarp left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice work

shard.yml Outdated Show resolved Hide resolved
@crimson-knight crimson-knight merged commit 5afa787 into amberframework:master May 3, 2023
9 of 13 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants