Rename Table not working in Exasol despite user having alter table privileges - exasolution

I am unable to rename a table in Exasol despite using having Alter Table privilege.
Created a user with Alter Table privilege and tried renaming a test table but it didn't worked.
The error that I receive is : [42500] insufficient privileges for renaming object Test_Table.
rename table DEMO.Test_Mahen to DEMO.Test_Mahen_Updated;
The above command should rename the table but it is not working. Is there any additional privilege that I need to give to the user for renaming tables.
The user has following privileges :
ALTER ANY TABLE
CREATE ANY TABLE
DELETE ANY TABLE
DROP ANY TABLE
EXECUTE ANY FUNCTION
EXECUTE ANY SCRIPT
UPDATE ANY TABLE
USE ANY CONNECTION

You may create a new role and change schema owner to this role. After that you may grant this role to users who should be able to update \ rename tables in this schema.
All operations within schema should be permitted with this technique, including renaming.

Related

Creating a Migration for Admin Users

How do I create a migration file which will create a user with the role of "admin"? I've written the following:
rails g migration User
How can I give a role of "admin" to this user?
Migrations may serve two functions:
The manipulation of structure in your database
The manipulation of data in your database
Generally speaking it is best practice to use them for the first, and to try to avoid the second (which may cause issues to an upgrade path down the line).
Your question is unclear regarding whether you're asking to create a User table with a column representing administrative privileges, or if you're trying to add an administrative user to an existing Users table.
If you are trying to create a User table, you will want to do the following:
rails g model users is_administrator:boolean other_column:type
Something along these lines will generate a migration (and matching model) allowing Users to be created, with a column containing what could be treated as administrative privileges.
On the other hand, if you already have a Users table, and are trying to add the ability to distinguish administrators from non-administrators, you would be better suited by something like this:
rails g migration add_is_administrator_to_users is_administrator:boolean
Finally, if you are asking how to add a User to the table Users which already exists and contains the column "is_administrator", I would encourage you to add the following line to db/seeds.rb:
User.create( is_administrator: true, other_column: 'other value' )
And then run the following line in the console
rake db:seed
If this doesn't make sense, I would encourage you to read up in Active Record Migrations, or (in the case that you choose to leverage the third method) Active Record Seeds.
You can have users and admin in same table and add one more column called "role" which will be boolean, which will decide if the current user is admin or not
rails g migration user role:boolean name
if role is false than it is not an admin.

Execute stored proc fails with GRANT EXECUTE because of table permissions

I have created a stored proc on schema X that does a select across 10+ tables that are in schema X and Y.
I created a database role DBRole and added a new AD Group Login to it.
I thought all I needed to do was grant execute on x.MyStoredProc to DBRole,
but I'm getting errors because of select permission..
Stored Procedure MYSCHEMA.MyStoredProc failed: The SELECT permission
was denied on the object 'myTable', database 'Db', schema 'dbo'.
I wondered if it was because the tables its failing on are in a different schema but, doing a quick test that still worked..
Can anyone explain what I'm missing?

Hstore and multitenancy

I'm bulding an app where users can add custom fields and submit data. I'm using Postgresql so I thought that Hstore would be the perfect solution for this. Also because it allows to query the custom data that the users may introduce. My problem is that Hstore can only be installed into one schema and I'm using apartment gem for multitenancy. So each User has one schema in the database.
The data into the Hstore column is private, so I don't want other users to get access to it. How can I acomplish this? I prefer to store this data into the same user's schema. Is there another solution?
Craig is telling you to install hstore in its own schema. That means doing something along these lines.
create schema hs;
create extension hstore with schema hs;
This has nothing to do with how and where you store hstore data.
If I had a personal schema named "mike", I would build tables in the "mike" schema with hstore data types like this.
create schema mike;
create table mike.test (
some_column_name hs.hstore
);
You can avoid having to use the "hs" schema name (as in "hs".hstore) by putting that schema in the search path. If you were doing a "normal" client/server application, you'd probably want to set it at the database level.
alter database your_database_name set search_path TO mike, hs, public;
But in your multi-tenant architecture, which has one schema per tenant, you'd probably want one database role per tenant, and you'd probably want to set the search path for each role. (I'm not familiar with the "apartment" gem; I presume it creates one role per tenant and one schema per tenant. Verify that by checking the database schema.)
alter role one_role_name set search_path to one_role_name, hs, public;
I'd also want to verify sensible privileges on the schemas. For example, in a multi-tenant architecture like yours, I'd want to verify that only "mike" has privileges in the "mike" schema.
The first schema in the search path becomes the default schema for new objects. On the other hand, database objects in that schema can hide database objects of the same name in other schemas. Keep that in the back of your mind.
Finally, thousands of rows is a tiny database. Performance problems will probably have nothing to do with your database search path.

updating the model based on the new database changes

I created a model "user" using the generate scaffold user command line. Next I made some changes to the database using generate migration command line and then updated the database using rake db:migration . Now I want to make my model in sync with the database fields automatically. Is it possible through a command line and if yes, how ? If not, what are the other options.
thanks
Your application find automacaly the change in your database if you don't specify a attr_accessible in your model. It make SQL requests to see all fields in the table. It's slower but simpler.

How do define the schema that a rails model is set to?

For instance, when I generate an Event model, the table automatically sets to the public schema. How do I specify it to get set to a different schema?
Furthermore, how do you alter the schema of an existing table? Perhaps move it to a different schema?
Thank you!
Disclaimer: I don't know rails, so I'm going to give very postgresql-oriented answers here. For the first part of your question, there is quite possibly a much better way to do this, by making rails specify the schema when creating tables.
In PostgreSQL, tables are searched for in schemas according to the search_path setting. This is set by default to "$user",public. Tables are created in the first schema found in the search path that exists. So if you connect as "my_user", it will try to create tables in "my_user", and fall back to creating them in "public" if "my_user" doesn't exist.
So one approach is to update the "search_path" setting used for the user you connect to the database to make schema changes. For example you can say ALTER USER my_user SET search_path = my_app, public. If you then create a "my_app" schema then subsequent CREATE TABLE foo(...) commands executed by "my_user" will put the new table into "my_app".
You can change the schema of a table using ALTER TABLE foo SET SCHEMA my_app.
Create a migration to generate your new schema. ActiveRecord can't update you schema to you it's the pattern system. You can try sequel or DataMapper if you want update you schema from your code.

Resources