ariga / entimport

A tool for generating Ent schema from SQL schema
Apache License 2.0
174 stars 49 forks source link

import failed - pq argument of AND must be type boolean #6

Closed richp10 closed 2 years ago

richp10 commented 2 years ago

Attempting to import from a postgres 13 database with this command:

go run ariga.io/entimport/cmd/entimport -dialect postgres -dsn "host=localhost port=5432 user=postgres dbname=testdb password=tesdbPass sslmode=disable" -tables "services"

It crashes with the error: entimport: schema import failed - postgres: querying schema tables: pq: argument of AND must be type boolean, not type information_schema.sql_identifier

If I do not include the -tables param, it crashes with: schema import failed - entimport: invalid primary key - single part key must be present

richp10 commented 2 years ago

I found that a table did not have a primary key - after adding this the result without specifying tables is:

entimport: schema writing failed - schemast: unsupported type TypeBytes

And if I specify a table (which I have checked does not have a Bytes field) I still get the other error:

entimport: schema import failed - postgres: querying schema tables: pq: argument of AND must be type boolean, not type information_schema.sql_identifier

zeevmoney commented 2 years ago

Hi @richp10 Thanks for reaching out.

richp10 commented 2 years ago

Thanks.. I have removed all the bytea fields so that is no longer an issue.

On the other error, it is still showing even without the byea fields and fixed primary keys. This is the DDL of one table that showed the same result with -tables "blogs"

SET statement_timeout = 0;
SET lock_timeout = 0;
SET idle_in_transaction_session_timeout = 0;
SET client_encoding = 'UTF8';
SET standard_conforming_strings = on;
SELECT pg_catalog.set_config('search_path', '', false);
SET check_function_bodies = false;
SET xmloption = content;
SET client_min_messages = warning;
SET row_security = off;

CREATE TABLE public.blogs (
    id integer NOT NULL,
    title character varying(50),
    body text,
    created_at timestamp without time zone DEFAULT now(),
    updated_at timestamp without time zone DEFAULT now(),
    slug character varying(55),
    key_words character varying(1000)
);

There are triggers to update the timestamps, and also to set the ID from a sequence - not included for clarity but let me know if you want a look.

The tables are in the 'public' schema (I tried table name as 'public.blogs' but it made no difference).

I am running PostgreSQL 13.4 on Windows

Let me know if there is anything else I can do to check / help - the project looks terrific and my schema is large and hand coding for ent would be a massive PITA !

zeevmoney commented 2 years ago

Hi again, and sorry for the long reply. We did some recent updates to Atlas and I've updated this package. Tried your schema:

SET statement_timeout = 0;
SET lock_timeout = 0;
SET idle_in_transaction_session_timeout = 0;
SET client_encoding = 'UTF8';
SET standard_conforming_strings = on;
SELECT pg_catalog.set_config('search_path', '', false);
SET check_function_bodies = false;
SET xmloption = content;
SET client_min_messages = warning;
SET row_security = off;

CREATE TABLE public.blogs
(
    id         integer NOT NULL,
    title      character varying(50),
    body       text,
    created_at timestamp without time zone DEFAULT now(),
    updated_at timestamp without time zone DEFAULT now(),
    slug       character varying(55),
    key_words  character varying(1000)
);

And go the follwoing:

// Code generated by entimport, DO NOT EDIT.

package schema

import (
    "entgo.io/ent"
    "entgo.io/ent/schema"
    "entgo.io/ent/schema/field"
)

type Blog struct {
    ent.Schema
}

func (Blog) Fields() []ent.Field {
    return []ent.Field{field.Int32("id"),
        field.String("title").Optional(),
        field.String("body").Optional(),
        field.Time("created_at").Optional(),
        field.Time("updated_at").Optional(),
        field.String("slug").Optional(),
        field.String("key_words").Optional()}
}
func (Blog) Edges() []ent.Edge {
    return nil
}
func (Blog) Annotations() []schema.Annotation {
    return nil
}

Try to update entimport to the latest version and run it again, should work fine now (except for the bytes field of course).