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

Migrating psql DB fails when using Decimal type on models #37

Closed
NZTimKeegan opened this issue Mar 20, 2018 · 1 comment
Closed

Migrating psql DB fails when using Decimal type on models #37

NZTimKeegan opened this issue Mar 20, 2018 · 1 comment
Assignees
Labels
bug Something isn't working
Milestone

Comments

@NZTimKeegan
Copy link

Expected Behavior

Database should be created including column for Decimal property

Actual Behavior

Thread 1: Fatal error points to line 179 of the file Decodable+CodingPath.swift (path: Core 3.0.0-rc.1.0.1/CodableKit/Key)

With logging enabled:

databaseConfig.enableLogging(on: .psql)

the output is:

Migrating psql DB
[psql] [2018-03-20 20:39:24 +0000] SELECT count(*) as "fluentAggregate" FROM "fluent" []
[psql] [2018-03-20 20:39:24 +0000] SELECT "fluent".* FROM "fluent" ORDER BY "fluent"."batch" DESC LIMIT 1 OFFSET 0 []
[psql] [2018-03-20 20:39:24 +0000] SELECT "fluent".* FROM "fluent" WHERE ("fluent"."name" = $1) LIMIT 1 OFFSET 0 ["7 bytes"]
[psql] [2018-03-20 20:39:24 +0000] SELECT "fluent".* FROM "fluent" WHERE ("fluent"."name" = $1) LIMIT 1 OFFSET 0 ["6 bytes"]
[psql] [2018-03-20 20:39:24 +0000] SELECT "fluent".* FROM "fluent" WHERE ("fluent"."name" = $1) LIMIT 1 OFFSET 0 ["18 bytes"]
[psql] [2018-03-20 20:39:24 +0000] SELECT "fluent".* FROM "fluent" WHERE ("fluent"."name" = $1) LIMIT 1 OFFSET 0 ["13 bytes"]

Steps to Reproduce the Problem

  1. Create new project (e.g. vapor new api-template --template=api --branch=beta )
  2. Add Postgres config
  3. Add decimal property to model
import FluentPostgreSQL
import Foundation
import Vapor

struct Todo: Content, Migration, Parameter, PostgreSQLModel {
  var id: Int?
  var decimal: Decimal
}
  1. Hit Run
    screen shot 2018-03-21 at 09 51 06

Specifications

  • Versions:
    • Vapor Toolbox 3.1.4
    • Swift 4.1
    • Xcode 9.3 beta 4
@tanner0101 tanner0101 added the bug Something isn't working label Mar 22, 2018
@tanner0101 tanner0101 self-assigned this Mar 22, 2018
@tanner0101 tanner0101 added this to the 1.0.0 milestone Jun 2, 2018
@tanner0101
Copy link
Member

Decimal encodes to JSON, like:

{"exponent":-3,"length":1,"isCompact":true,"isNegative":true,"mantissa":[1234,0,0,0,0,0,0,0]} (JSONB)

This is desired since it allows the type to store values with higher precision than Float and Double. I've added a test to make sure this is working in the latest build, just make sure to use a JSONB column type 👍 .

tanner0101 added a commit that referenced this issue Jun 2, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants