How to set the default function for #PrimaryGeneratedColumn when I set the entity with TypeORM - typeorm

I'm planning to upgrade my Postgres database from v10 to v13, since the uuid-ossp module is no longer under maintenance for Postgres v13, so I'm trying to update the default uuid generation function from uuid_generate_v4() to gen_random_uuid()
The entity I had before was:
#PrimaryGeneratedColumn('uuid')
id: string;
Since the #PrimaryGeneratedColumn('uuid') is default to use uuid_generate_v4(), and I want to update the default function to gen_random_uuid(), however it doesn't support this kind of customization according to their official doc.
any help please?

Related

Rails PostgreSQL check if column is virtual

PostgreSQL 12 has a cool Generated Columns feature but I can't check whether column is virtual or not in Rails.
For reference, MySQL Adapter in Rails allows you to do like
MyModel.supports_virtual_columns?
=> true
MyModel.columns.last.virtual?
=> false
But in PostgreSQL Adapter you can't do the same despite it does support Generated fields?
Rails v.5.1.7
The fact that PostgreSQL 12 implements generated columns doesn't mean that you're going to have the interface through the Rails PostgreSQLAdapter to check whether a column is virtual or not because it's not implemented (yet).
If you see in the ActiveRecord::ConnectionAdapters::AbstractMysqlAdapter the code for supports_virtual_columns? is pretty simple:
def supports_virtual_columns?
mariadb? || database_version >= "5.7.5"
end
While the code to check if a column is virtual or not is stated as:
def virtual?
/\b(?:VIRTUAL|STORED|PERSISTENT)\b/.match?(extra)
end
Which checks if the Extra value returned from a
SHOW FULL FIELDS FROM table_name;
query for that column matches with VIRTUAL, STORED or PERSISTENT, if so, it returns true.
But this doesn't exist in the PostgreSQL counterpart. supports_virtual_columns? will return false in any adapter where this feature isn't developed, as it's defined in the ActiveRecord::ConnectionAdapters::AbstractAdapter to return false:
# Does this adapter support virtual columns?
def supports_virtual_columns?
false
end
the function is been added for postgresql since rails 7
so you could just do MyModel.columns.last.virtual? like when using mysql

Mongo::Error::OperationFailure Unknown modifier: $pushAll when updating a model (mongoid, angular, rails)

I am using angular-8 on the front-end and Rails(5.2) on backend with Mongoid(6.1).
I have a multi-level nested form for model Event that accepts_nested_attributes_for Ticket that in turn accepts_nested_attributes_for Channel.
Whenever I try to update any event and add new Channel to any Ticket with in event. I receive this error:
Mongo::Error::OperationFailure (Unknown modifier: $pushAll. Expected a valid update modifier or pipeline-style update specified as an array (9)):
I have looked it up and found here, that $pushAll support is deprecated now and we have to Turn on UsePushEach by default.
But I can't figure out where should I configure this UsePushEach by default settings in Rails.
Any help would be appreciated. Thanks!
Note that you're referring to the Github issue of Mongoose which is a node ODM and you're trying to apply their setup to Rails. They are quite different and their issues and solutions do not apply to each other.
In Mongoid, pushAll were removed since Mongoid 6.3 (see MONGOID-4499). You're seeing this error because you're using an old version of Mongoid.
Upgrading to the latest Mongoid (currently 7.0) should remove this error.
using $push you can use both single value and array of value
Both are valid
{"$push":{"column1":"value"}} // push individual value to column1 array type
{"$push":{"column1":[value]}} // append entire array to column1 array type(internally mongodb will use $each)

HANA xsodata create using procedure

Trying to create xsodata via dbprocedure
"X"."SHOPLIST/Header" as "Header"
navigates ("ToItem" as "ItemRef")
create using "X"."SHOPLIST.shoplist::create";
it says Syntax error at line: 3, column: 15.
create using "SHOPLIST.shoplist::create";
it says Unknown object "SHOPLIST.shoplist::create".
Procedure name is "X"."SHOPLIST.shoplist::create" (it works ok in console).
So it seems that xsodata doesn't work with DB artifacts. I had to create .hdbprocedure and then it would accept it without schema prefix...

Odoo 10 web service api not updating object in ruby on rails

I'm trying to update an existing product's QoH (quantity on hand) in the Odoo 10 database with new values via the web service API to sync the data from our e-store. I'm doing it throw a rails app.
I've debugged and apparently the Odoo side is just not updating the record. Do you have some thoughts on what could it be?
#models.execute_kw(#db, #uid, #password, 'product.product', 'write', [[odoo_product_id], {
qty_available: new_qoh
}])
And when I read again the object:
#models.execute_kw(#db, #uid, #password, 'product.product', 'read', [odoo_product_id], {fields: %w(x_code qty_available)})
The quantity_available still the same old one.
That's just because qty_available is a computed field without inverse method, which should be there if you want to write into the field. You will need to create stock.quants for the product or just use the mechanism to update the quantity on hand (a wizard, which can be used by web api, too).

Postgres Query to find whether database is read-only mode

I am new to postgres. In mysql we can check whether the database is in read-only mode by triggering the below query.
SELECT ##global.read_only
Likewise can anyone pls help me with the query to do the same in postgres? I tried few things like below
SELECT schemaname||'.'||tablename FROM pg_tables
WHERE
has_table_privilege ( 'postgres', schemaname||'.'||tablename, 'select' )
AND schemaname NOT IN ( 'pg_catalog','information_schema');
But it is listing like below which I am not expecting.
?column?
----------------------------------------
public.schema_migrations
public.credential_methods
public.notifications
public.site_defaults
public.apis
public.client_applications
public.api_groups
public.operations
public.client_application_labels
public.client_application_label_values
public.roles
public.users
public.sdm_user_roles
public.permissions_roles
public.keys
public.o_two_access_tokens
public.settings
public.sdm_users
public.permissions
public.audits
public.oauth_requesttokens
public.oauth_access_tokens
public.oauth_verifiers
public.logged_exceptions
public.api_call_details
public.api_access_roles
public.api_access_users
public.login_attempts
public.system_scopes
public.keys_system_scopes
public.o_two_auth_codes
public.o_two_refresh_tokens
public.service_profiles
public.error_traces
I also tried "\du" but this one is working only in terminal but not from a ruby file.
query=ActiveRecord::Base.connection.execute("\du;")
ActiveRecord::StatementInvalid: PGError: ERROR: syntax error at or near "du"
LINE 1: du;
Thanks,
Rafiu
You probably want something of the has_*_privilege() family function for relevant tables and relevant privileges. See here. Other than that I'm not sure if postgres has a concept of read-only mode.
Well, there's also show transaction_read_only inside a read-only transaction, but that doesn't seem to be like what you're asking for. And I don't think that transaction being readonly affects privileges of the user.
I'm not sure what you expect from your query, but if you want something boolean, as in whether you have access anywhere, you can use count(*)!=0 (and, probably, not select).
If you have a multi-node instance cluster, and you have the hot standby configuration. The output of SELECT pg_is_in_recovery() can tell you if the cluster is in the read-only mode.

Resources