can I create tables and RLS via any external API or similar? - supabase

I need to create a custom admin tool, where I create tables and RLS rules outside the Supabase admin dashboard.
Is this possible?

You can use any database interaction tool to do this. I am using a nodejs database migration tool in one of my project along with a nodejs postgres client and I'm able to create tables, enable RLS and write policies with this. You can see all the files doing these tasks in my project here.

Found out in the documentation for RLS, and in combination with the SQL editor (https://supabase.com/docs/guides/auth/row-level-security)
Wrap this bit in a database function with parameters
-- 1. Create table
create table profiles (
id uuid references auth.users,
avatar_url text
);
-- 2. Enable RLS
alter table profiles
enable row level security;
-- 3. Create Policy
create policy "Public profiles are viewable by everyone."
on profiles for select using (
true
);
Then call the function with rpc call

Related

How to use spatie / laravel-multitenancy with single database?

I want to convert my existing app to multi-tenant and don't want to use multiple databases. just read that the given package is allowing that.
https://github.com/spatie/laravel-multitenancy
I have read the single database documentation here: https://spatie.be/docs/laravel-multitenancy/v2/installation/using-a-single-database
But what's next ??
Let's say right now users are storing into users' tables, and by using this package I want to store users tenant-specific.
I don't found the real example anywhere. so better if anyone already implemented Spatie Multi-tenant by using a single Database, please help me here.
Thanks in advance.
Although spatie/laravel-multitenancy supporting single databases, it doesn't come with query scopes (and seems like there are no plans to add them, as you can see here: https://github.com/spatie/laravel-multitenancy/issues/124), so you would need to create them manually.
So, you need to:
add the tenant_id to your tenant-specific tables
add an observer to save the tenant_id when creating a new register in the table
add a global query scope to always filter the data using the current tenant id
You can see something similar in this video: https://www.youtube.com/watch?v=nCiNqboYFVQ
The difference is that you will use the current tenant returned by spatie/laravel-multitenancy instead of the logged user id to get the tenant data.
If you want a package that already brings the query scopes ready to use, you may try Tenancy for Laravel: https://tenancyforlaravel.com/docs/v3/single-database-tenancy
Or, if your application has a very simple multi-tenancy strategy (for example, the tenant is the logged user or his team) you can just create some query scopes without the need to use packages, exactly as the video above teaches, as it is much more simple to identify the tenant by the user_id or team_id, even in terminal commands and queue jobs (but seems that is not your case, as you need the users to belongs to a tenant).
I hope it helps you to select the correct package and strategy for your project.

Oracle Apex: Is it possible to change the default schema at runtime?

We have an Apex application (version 20.1) and our users must be able to change the database schema at runtime via button click (preferably without logging in again).
Currently we are solving this by installing our application multiple times, once per schema.
We recently discovered the function apex_export.get_application. We intend to use this function to bring our frontend under version control (finally!). We would like to deploy our application directly from the exported files. Having a single application, we would not have to mess with the internal component ids from the exported files.
Is it possible to install the application once and change the default schema via Pl/SQL code? Thank you!
I don't think this can be done, but perhaps the following is a reasonable compromise
add all the schemas you need to support to the workspace schema list
Any SQL (and I do mean any) in your app would be prefixed with an application item, eg
Before: select * from my_table
After: select * from &my_schema..my_table
At login time (or when a user selects it) you modify the MY_SCHEMA application item
(I've not tried this...so test/tread carefully)

Oracle Apex 19.2: Cannot resolve the "schema is reserved or restricted" issue

I attempted to create a workspace in APEX using an existing schema called PEOPLE and it gave the error message "The schema is reserved or restricted". I tried with other existing schemas that I created and they all worked fine.
Technical/Environment details follow:
Database: Oracle 19c EE installed on local machine.
Apex: 19.2 installed as Embedded Gateway on local machine.
Created pluggable database called PDB1.
Created tablespace PEOPLE_TAB using OMF (Oracle Managed Files) syntax.
Created local user PEOPLE in PDB1.
Gave PEOPLE the following roles and privs (I'm aware some are doubled up like RESOURCE role and CREATE SESSION priv):
RESOURCE
UNLIMITED TABLESPACE
SELECT_CATALOG_ROLE
CREATE SESSION
CREATE TABLE
CREATE TYPE
CREATE CLUSTER
CREATE TRIGGER
CREATE PROCEDURE
CREATE SEQUENCE
CREATE VIEW
CREATE DIMENSION
CREATE JOB
CREATE SYNONYM
CREATE DIMENSION
CREATE MATERIALIZED VIEW
I created another user TEST1 in the same tablespace PEOPLE_TAB, with the same privs as PEOPLE and re-created the objects and data. I could successfully create a workspace using this new schema!
Trawled the web, but most articles and posts refer to older versions of APEX, but I still tried the following.
I followed the advice given in the Oracle docs, Application Express Release 19.2 Adminstration Guide section 2.13
The APEX engine schema for APEX 19.2 is APEX_190200. So I unlocked APEX_190200 and logged in (after changing password) to run the checks.
-- Checked if PEOPLE was a restricted schema
SELECT schema FROM APEX_190200.wwv_flow_restricted_schemas order by schema;
PEOPLE is not listed and I assume is not restricted. So I tried to unrestrict PEOPLE anyway as detailed in the docs.
-- ran from APEX_190200
EXEC APEX_INSTANCE_ADMIN.UNRESTRICT_SCHEMA(p_schema => 'PEOPLE');
COMMIT;
Successfully ran but did not resolve the issue.
Looking on the web most of the info was out of date but tried anyway.
-- ran from APEX_190200
EXEC APEX_SITE_ADMIN_PRIVS.UNRESTRICT_SCHEMA(p_schema => 'PEOPLE');
COMMIT;
The above did not run and complained the package didn't exist. I verified that when looking for APEX_SITE_ADMIN_PRIVS in user_objects - it was not there.
Some years ago there was a bug with the function wwv_flow_provision.IS_RESERVED, but I checked this and it ran ok returning FALSE for PEOPLE and TRUE for reserved words like VARCHAR.
It's really thrown me when I can create an identical user (different name) with identical privs, objects and data was created on the same tablespace and it worked fine with an APEX workspace.
Does anyone have any experience of resolving this issue or point me in the right direction?
Thank you.
You are receiving the error because PEOPLE is specified as a restricted schema with an APEX package.
In the installation scripts for APEX 19.2, the file named f4050.sql has a page validation on page 79 (the page that is raising the error) that looks like this:
...
...
...
wwv_flow_api.create_page_validation(
p_id=>wwv_flow_api.id(114752711027135415)
,p_validation_name=>'schema not reserved/restricted'
,p_validation_sequence=>80
,p_validation=>wwv_flow_string.join(wwv_flow_t_varchar2(
'wwv_flow_provision.schema_name_valid(',
' p_schema => :F4050_P79_SCHEMA,',
' p_workspace_name => :F4050_P27_COMPANY);'))
,p_validation_type=>'PLSQL_EXPRESSION'
,p_error_message=>'Schema is reserved or restricted'
,p_when_button_pressed=>wwv_flow_api.id(12559200978895311)
,p_error_display_location=>'INLINE_WITH_FIELD_AND_NOTIFICATION'
);
...
...
...
Then using a procedure block like this, you can determine if the schema name is valid or not:
BEGIN
IF apex_190200.wwv_flow_provision.schema_name_valid (p_schema => 'PEOPLE',
p_workspace_name => 'PEOPLE')
THEN
DBMS_OUTPUT.put_line ('Valid');
ELSE
DBMS_OUTPUT.put_line ('Invalid');
END IF;
END;
/
Then by unwrapping the code in those packages (tools can be easily found online). Within that code, there is a call to another function named WWV_FLOW_PROVISIONING.RESERVED_SCHEMA (P_SCHEMA => P_SCHEMA). Within that function, there is code that looks like this:
IF C_SCHEMA IN (
'HTMLDB_PUBLIC_USER',
'APEX_PUBLIC_USER',
'PUBLIC_USER',
'FLOWS_FILES',
'SCHEDULER',
'PEOPLE') THEN
RETURN TRUE;
END IF;
So without modifying the package WWV_FLOW_PROVISIONING (which I would highly recommend AGAINST), you will not be able to create an APEX workspace with the schema name PEOPLE. This will need to be fixed by Oracle either through a patch to the package or in a newer version of APEX.
Fascinating issue. The restricted schema is hard-coded in APEX provisioning code. It's very much a legacy issue.
We can attempt to fix this in the next release of APEX, but that won't help you now. If you file a Service Request for Oracle Support, I'll make sure you get a fix for this issue (assuming you're using a supported version of APEX).

Is there a way to find out if my package or table is accessed via a DB Link

Is there a way to find out if my package or table is accessed via a DB Link?
I have a schema which is accessed via db link and direct connection. I can get the dependencies fine, but I really would like to see if there is a way to tell if the object used is via a db link vs direct connection.
select * from dba_dependencies d , dba_synonyms s
where d.owner in ('MY_SCHEMA')
and d.referenced_owner = 'PUBLIC'
and d.referenced_type='SYNONYM'
and d.referenced_name = s.synonym_name
and s.owner='PUBLIC'
and s.table_owner not in ('MY_SCHEMA')
Is there a way other than checking the remote databases. I would prefer to do this from the source database.
Using user_db_links. db links accessibility is based on schema not by indivial objects like package, procedure, table etc

MVC3 EDMmetadata table not found

I am new in MVC3 i am going to create a MVC3 test project where i am create model class name WhiteAccount with ID,Name,Email,Password property. and successfully create a DB but when i add another new property in that WhiteAccount model class and in my DB table too but it give me some error. Some people say just delete the EDMmetadata table from your DB, But Here is the problem i have no EDMmetadata table in my DB ! I create my DB by EntityFramework v4.3.1 system automatically (CodeFirst). What should i do now ?
Check for the __MigrationHistory table.
Open the nuget package manager console and run
update-database -script
It will likely give you a message about having to enable it first, follow those directions
Run: Enable-Migrations
some more info on migrations
http://blogs.msdn.com/b/adonet/archive/2012/02/09/ef-4-3-code-based-migrations-walkthrough.aspx
Im gathering this table is there in your db (under system tables) and it contains your model information. Since your project changed you need to tell the migrations about the new field or delete the table (__MigrationsHistory)

Resources