Add same role in rights module gives me Integrity constraint violation error - yii

I am currently working on rights module. i add trade_company_id in authitem table. so when different company add same role it should allowed. but it gives me Integrity constraint violation: 1062 Duplicate entry 'companyadmin' for key 'PRIMARY'. The SQL statement executed was: INSERT INTO authitem (name, type, description, bizrule, data) VALUES (:name, :type, :description, :bizrule, :data) Error.
What i should do?

Related

How to add a conditional unique constraint in Liquibase?

Problem: When a user is deleted the associated record is not deleted from the database. Instead, I set user.delete column to true. Now I need to put a unique constraint on user.email but only for active users (not deleted).
How can I do this?
databaseChangeLog:
- changeSet:
id: add-user-unique-constraint
author: me
changes:
- addUniqueConstraint:
columnNames: email, delete
constraintName: unique-email-not-deleted
tableName: users
The above naive approach puts a composite constraint on (email, delete) columns, but it doesn't work because in the following flow user is blocked from deleting and creating an account:
register a new user with email "E"
delete the user with email "E"
register again new user with email "E"
delete the user with email "E" -> error: constraint violation
register new user with email "E" -> error: constraint violation
ps. databases are H2 and PostgreSQL
This feature is DB-specific and currently liquibase doesn't support it.
For PostgreSQL you may use direct SQL:
databaseChangeLog:
- changeSet:
id: add-user-unique-constraint
author: me
changes:
- sql:
"sql": "CREATE UNIQUE INDEX user_email_idx ON user (email) WHERE delete = 'false'"
however this will NOT work in H2.
Possible options for H2:
if it's used in tests then you may migrate to PostgreSQL using testcontainers technology (but your build environment will depend on docker)
have custom changesets for PostgreSQL and H2 - you may use preconditions

Integrity Error duplicate key value violates unique constraint "hr_attendance_pkey"

I am using mobile app for sign in and sign out into the hr attendance.I am accessing the database of postgresql of odoo and saving the data.When I sign in from web application of odoo then I sign out from mobile.Now again I am trying to sign in from web application.It is showing the following error.
Integrity Error
duplicate key value violates unique constraint "hr_attendance_pkey"
DETAIL: Key (id)=(114) already exists.

CDbCommand failed to execute the SQL statement: SQLSTATE[42S22]

I'm working with yii users and rights and following this link, http://www.yiiframework.com/wiki/423/installing-yii-users-and-rights-to-newly-created-yii-app/
I have applied all the things mentioned in this link, but when i type the url localhost/webapp/user/login it asks me to login. Upon login i get this error :
CDbCommand failed to execute the SQL statement: SQLSTATE[42S22]:
Column not found: 1054 Unknown column 'id' in 'field list'. The SQL
statement executed was: SELECT id, username, email, createtime,
lastvisit, superuser, status, password, activkey FROM user t WHERE
t.username=:yp0 LIMIT 1
Please help me with this..!!
make sure you have a column "id" in the user table. In Yii, id is the default primary key as well

Liquibase db update fails saying DATABASECHANGELOGLOCK is already an existing object

I am trying to log in as user account and create synonyms for all objects available in owner account, using liquibase changeset. I am getting below error when running the liquibase.integration.commandline.Main.
liquibase: Executing EXECUTE database command: CREATE TABLE SSEAPSL_USER_01.DATABASECHANGELOGLOCK (ID NUMBER(10) NOT NULL, LOCKED NUMBER(1) NOT NULL, LOCKGRANTED TIMESTAMP, LOCKEDBY VARCHAR2(255), CONSTRAINT PK_DATABASECHANGELOGLOCK PRIMARY KEY (ID))
Unexpected error running Liquibase: java.sql.SQLException: ORA-00955: name is already used by an existing object
SEVERE 20/07/15 12:39: liquibase: java.sql.SQLException: ORA-00955: name is already used by an existing object
liquibase.exception.LockException: liquibase.exception.DatabaseException: java.sql.SQLException: ORA-00955: name is already used by an existing object
at liquibase.lockservice.StandardLockService.acquireLock(StandardLockService.java:215)
But the user account doesn't have DATABASECHANGELOGLOCK table created. Only Owner account has that table. Please could someone help me how can I resolve this issue?
When using Oracle, if you use user credentials in your liquibase connection, the schema that Liquibase will want to use is the schema for that user. You should be able to work around this by specifying the name of the schema you actually want to manage (the owner schema).
You didn't specify, but it looks like you might be using the command line to run Liquibase. If that is the case, you can specify --defaultSchemaName=ownerschema on the command line.
http://www.liquibase.org/documentation/command_line.html

Delete a user in database with name user1;

I have a user in the database with the username "USER1;" including the semicolon.
How to remove this user?
When I tried with
SQL> drop user user1; cascade;
drop user user1; cascade
*
ERROR at line 1:
ORA-00911: invalid character
How to remove this user then?
Note: Database Oracle 11g
You have to enclose the name in double quotes if it contains characters that aren't allowed in non-quoted names:
drop user "USER1;" cascade;
The user must have been created in the same way. Note that Oracle does not recommend using quoted identifiers (including, by implication, user names). Trying to refer to objects in that user's schema would have been a pain.