Skip to content
This repository has been archived by the owner on Sep 7, 2021. It is now read-only.
This repository is currently being migrated. It's locked while the migration is in progress.

something wrong when using xorm reverse on unique index #1183

Closed
xuyz opened this issue Jan 3, 2019 · 5 comments
Closed

something wrong when using xorm reverse on unique index #1183

xuyz opened this issue Jan 3, 2019 · 5 comments

Comments

@xuyz
Copy link
Contributor

xuyz commented Jan 3, 2019

error message

[Error] reverse.go:178 Unknown col is_default) WHERE in index userc_addr_userc_id_is_default_key of table userc_addr, columns [id userc_id name phone city area detail is_default create_time area_id city_id]

the table

create table userc_addr(
  id bigserial primary key,
  userc_id bigint REFERENCES userc(id),
  name varchar(128),
  phone varchar(11),
  city varchar(128),
  area varchar(128),
  detail text,
  is_default boolean DEFAULT FALSE,
  create_time timestamp with time zone,
  area_id int,
  city_id int
);
CREATE UNIQUE index userc_addr_userc_id_is_default_key on userc_addr(userc_id, is_default) where is_default=true;
CREATE index userc_addr_userc_id_idx on userc_addr(userc_id);

@xuyz
Copy link
Contributor Author

xuyz commented Jan 3, 2019

the sql of userc table

create table userc(
  id bigserial primary key,
  phone varchar(11),
  create_time timestamp with time zone,
  UNIQUE(phone)
);

@xuyz
Copy link
Contributor Author

xuyz commented Jan 3, 2019

moved cmd

@xuyz xuyz closed this as completed Jan 3, 2019
@xuyz xuyz reopened this Jan 28, 2019
@xuyz
Copy link
Contributor Author

xuyz commented Jan 28, 2019

I think the problem is here.

cs := strings.Split(indexdef, "(")
colNames = strings.Split(cs[1][0:len(cs[1])-1], ",")

when execute
SELECT indexname, indexdef FROM pg_indexes WHERE tablename='userc_addr' and schemaname='public';
got indexdef
CREATE UNIQUE INDEX userc_addr_userc_id_is_default_key ON public.userc_addr USING btree (userc_id, is_default) WHERE (is_default = true)

I can submit a pull request if necessary.

@xuyz
Copy link
Contributor Author

xuyz commented Jan 28, 2019

@lunny

@lunny
Copy link
Member

lunny commented Jan 28, 2019

@xuyz please send a PR and better if you can add some tests

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants