sql-adapter
sql-adapter copied to clipboard
AddPolicy always returns true
I migrated my code to use AddPolicy in an effort to remediate https://github.com/Blank-Xu/sql-adapter/issues/10.
I have a unique constraint on my casbin_rule table, and this method seems to handle that just fine. It does not fail (unlike AddPoliciesEx with the unique constraint.)
However, it always returns true as if it added the policy, even though it already exists on the backend.
CREATE TABLE casbin_rule (
p_type varchar(32) DEFAULT ''::character varying NOT NULL,
v0 varchar(255) DEFAULT ''::character varying NOT NULL,
v1 varchar(255) DEFAULT ''::character varying NOT NULL,
v2 varchar(255) DEFAULT ''::character varying NOT NULL,
v3 varchar(255) DEFAULT ''::character varying NOT NULL,
v4 varchar(255) DEFAULT ''::character varying NOT NULL,
v5 varchar(255) DEFAULT ''::character varying NOT NULL,
created_at timestamptz DEFAULT CURRENT_TIMESTAMP NOT NULL,
updated_at timestamptz DEFAULT CURRENT_TIMESTAMP NOT NULL
);
CREATE INDEX idx_casbin_rule ON casbin_rule USING btree (p_type, v0, v1);
CREATE UNIQUE INDEX idx_casbin_rule_unique_policy ON casbin_rule USING btree (p_type, v0, v1, v2, v3, v4, v5);
This is with postgres v15
So the two things that are puzzling to me with this method:
- Why does it handle the unique constraint (yet the AddPoliciesEx doesn't?)
- Why is it always returning
truefor the added field, even if the policy already exists?
Some relevant code for what I'm doing: https://github.com/nucleuscloud/neosync/pull/2935/files#diff-3ea50e3768ff6ddcdce9da5129f8b35a618f8dc0310292e3e9ea8dfa6d1bb873