Skip to content

Commit

Permalink
Merge pull request #4199 from mathesar-foundation/master
Browse files Browse the repository at this point in the history
Merge pull request #4152 from mathesar-foundation/0.2.0
  • Loading branch information
pavish authored Jan 28, 2025
2 parents 5bd0a28 + a5328e9 commit 54b2098
Show file tree
Hide file tree
Showing 55 changed files with 2,094 additions and 474 deletions.
2 changes: 1 addition & 1 deletion .env.example
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
ALLOWED_HOSTS='.localhost, 127.0.0.1, [::1]'
ALLOWED_HOSTS=.localhost,127.0.0.1,[::1]
SECRET_KEY=2gr6ud88x=(p855_5nbj_+7^bw-iz&n7ldqv%94mjaecl+b9=4
2 changes: 1 addition & 1 deletion api_tests/test_happy_db_setups.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ def intern_session():
"new_password1": "myinternpass1234",
"new_password2": "myinternpass1234"
}
s.post(f'{SERVICE_HOST}/auth/password_reset_confirm', data=reset_payload)
s.post(f'{SERVICE_HOST}/auth/password_reset_confirm/', data=reset_payload)
s.headers['X-CSRFToken'] = s.cookies['csrftoken']
new_login_payload = {"username": "intern", "password": "myinternpass1234"}
s.post(f'{SERVICE_HOST}/auth/login/', data=new_login_payload)
Expand Down
1,184 changes: 1,184 additions & 0 deletions db/sql/00_msar_all_objects_table.sql

Large diffs are not rendered by default.

98 changes: 44 additions & 54 deletions db/sql/02_msar_remove.sql
Original file line number Diff line number Diff line change
@@ -1,73 +1,62 @@
CREATE SCHEMA IF NOT EXISTS msar;


CREATE OR REPLACE FUNCTION
msar.drop_all_msar_objects(
schemas_to_remove text[],
remove_custom_types boolean DEFAULT true,
strict boolean DEFAULT true,
retries integer DEFAULT 5
strict boolean DEFAULT true
) RETURNS void AS $$/*
Drop all functions in the passed schemas, including this one.
Then drop the schemas themselves.
*/
DECLARE
i integer;
obj RECORD;
sch text;
detail text;
message text;
failed boolean := false;
retry boolean := false;
BEGIN
FOR obj IN
(
SELECT oid, oid::regprocedure::text AS obj_name,
CASE prokind
WHEN 'a' THEN 'AGGREGATE'
WHEN 'p' THEN 'PROCEDURE'
ELSE 'FUNCTION'
END AS obj_kind
FROM pg_proc
WHERE pronamespace::regnamespace::text=ANY(schemas_to_remove)
AND NOT ( -- Keep this up to date with this function's name and arguments.
proname = 'drop_all_msar_objects'
AND proargtypes=ARRAY[
'text[]'::regtype, 'boolean'::regtype, 'boolean'::regtype, 'integer'::regtype
]::oidvector
)
) UNION (
SELECT oid, oid::regtype::text AS obj_name, 'TYPE' AS obj_kind
FROM pg_type
WHERE typnamespace::regnamespace::text=ANY(schemas_to_remove)
AND typcategory <> 'A'
AND (remove_custom_types OR typnamespace::regnamespace::text <> 'mathesar_types')
) UNION (
SELECT oid, oid::regclass::text AS obj_name, 'TABLE' AS obj_kind
FROM pg_class
WHERE relnamespace::regnamespace::text=ANY(schemas_to_remove) AND relkind='r'
)
ORDER BY oid
LOOP
BEGIN
EXECUTE format('DROP %s %s', obj.obj_kind, obj.obj_name);
EXCEPTION
WHEN dependent_objects_still_exist THEN
failed = true;
GET STACKED DIAGNOSTICS
message = MESSAGE_TEXT,
detail = PG_EXCEPTION_DETAIL;
RAISE NOTICE E'% \nDETAIL: %\n\n', message, detail;
IF retries > 0 THEN
retry = true;
END IF;
WHEN undefined_function OR undefined_table OR undefined_object THEN
-- Do nothing.
END;
INSERT INTO msar.all_mathesar_objects
SELECT oid::regclass::text AS obj_name, 'TABLE' AS obj_kind, null AS custom_type
FROM pg_class
WHERE
relnamespace::regnamespace::text='mathesar_inference_schema'
AND relkind='r'
AND relname LIKE 'mathesar_temp_table%'
ON CONFLICT DO NOTHING;

INSERT INTO msar.all_mathesar_objects
SELECT oid::regprocedure::text AS obj_name, 'FUNCTION' AS obj_kind, null AS custom_type
FROM pg_proc
WHERE pronamespace::regnamespace::text='msar' AND proname='drop_all_msar_objects'
ON CONFLICT DO NOTHING;

SET client_min_messages = WARNING;
FOR i in 1..10 LOOP
FOR obj IN
SELECT obj_schema, obj_name, obj_kind, custom_type
FROM msar.all_mathesar_objects
WHERE
obj_schema=ANY(schemas_to_remove)
AND (remove_custom_types OR custom_type IS NOT true)
AND NOT (obj_name='msar.all_mathesar_objects')
LOOP
BEGIN
EXECUTE format('DROP %s IF EXISTS %s', obj.obj_kind, obj.obj_name);
EXCEPTION
WHEN dependent_objects_still_exist THEN
IF i >= 10 THEN
failed = true;
END IF;
GET STACKED DIAGNOSTICS
message = MESSAGE_TEXT,
detail = PG_EXCEPTION_DETAIL;
RAISE WARNING E'% \nDETAIL: %\n\n', message, detail;
END;
END LOOP;
END LOOP;
IF retry IS true THEN
PERFORM msar.drop_all_msar_objects(schemas_to_remove, remove_custom_types, strict, retries - 1);
ELSIF failed IS TRUE AND NOT strict THEN
SET client_min_messages = NOTICE;
IF failed IS TRUE AND NOT strict THEN
RAISE NOTICE 'Some objects not dropped!';
ELSIF failed IS TRUE AND strict THEN
RAISE EXCEPTION USING
Expand All @@ -78,7 +67,8 @@ BEGIN
;
ELSE
RAISE NOTICE E'All objects dropped successfully!\n\nDropping Mathesar schemas...\n\n';
DROP FUNCTION msar.drop_all_msar_objects(text[], boolean, boolean, integer);
DROP FUNCTION IF EXISTS msar.drop_all_msar_objects(text[], boolean, boolean);
DROP TABLE IF EXISTS msar.all_mathesar_objects;
FOREACH sch IN ARRAY schemas_to_remove
LOOP
IF remove_custom_types OR sch <> 'mathesar_types' THEN
Expand Down
4 changes: 2 additions & 2 deletions db/sql/05_msar.sql
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
SELECT msar.drop_all_msar_objects(
schemas_to_remove => ARRAY['msar', '__msar', 'mathesar_types'],
schemas_to_remove => ARRAY['msar', '__msar', 'mathesar_types', 'mathesar_inference_schema', 'msar_views'],
remove_custom_types => false,
strict => false
);
Expand Down Expand Up @@ -5660,7 +5660,7 @@ DECLARE
BEGIN
EXECUTE format(
$q$
WITH insert_cte AS (%1$s RETURNING %2$s)
WITH insert_cte AS (%1$s RETURNING %2$I)
SELECT *
FROM insert_cte
$q$,
Expand Down
2 changes: 2 additions & 0 deletions db/sql/install.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ def _install(conn):


INSTALL_STEPS = [
_install_sql_file("00_msar_all_objects_table.sql"),
_install_sql_file("01_msar_types.sql"),
_install_sql_file("02_msar_remove.sql"),
_install_sql_file("05_msar.sql"),
Expand All @@ -41,6 +42,7 @@ def uninstall(
strict=True
):
"""Remove msar and __msar schemas safely."""
_install_sql_file("00_msar_all_objects_table.sql")(conn)
_install_sql_file("02_msar_remove.sql")(conn)
exec_msar_func(
conn,
Expand Down
22 changes: 22 additions & 0 deletions db/sql/test_sql_functions.sql
Original file line number Diff line number Diff line change
Expand Up @@ -4431,6 +4431,28 @@ END;
$$ LANGUAGE plpgsql;


CREATE OR REPLACE FUNCTION test_add_record_to_table_pkey_quoting() RETURNS SETOF TEXT AS $$
DECLARE
rel_id oid;
BEGIN
PERFORM __setup_add_record_table();
ALTER TABLE atable RENAME COLUMN id TO "ID";
rel_id := 'atable'::regclass::oid;
RETURN NEXT is(
msar.add_record_to_table(
rel_id,
'{}'
),
$a${
"results": [{"1": 4, "2": 200, "3": null, "4": null, "5": null}],
"linked_record_summaries": null,
"record_summaries": null
}$a$
);
END;
$$ LANGUAGE plpgsql;


CREATE OR REPLACE FUNCTION test_add_record_to_table_stringified_json() RETURNS SETOF TEXT AS $$
DECLARE
rel_id oid;
Expand Down
4 changes: 2 additions & 2 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,8 @@ x-config: &config

# (Optional) Replace 'mathesar' with any custom password for the
# aforementioned database

POSTGRES_PASSWORD: ${POSTGRES_PASSWORD:-mathesar}

# (Optional) Replace 'mathesar_db' with the name of the host running postgres
POSTGRES_HOST: ${POSTGRES_HOST:-mathesar_db}

Expand All @@ -79,7 +79,7 @@ x-config: &config
# or https(port 443), also automatically creating SSL certificates
# for the same. If you want to host an instance of Mathesar over the
# internet or over your local network, add those domains here.
# Example: yourdomain.com, *.subdomain.com, 127.0.0.1
# Example: yourdomain.com,*.subdomain.com,127.0.0.1
#
# POSTGRES_DB:
# Default: mathesar_django
Expand Down
3 changes: 0 additions & 3 deletions docs/docs/administration/backup-restore.md

This file was deleted.

8 changes: 3 additions & 5 deletions docs/docs/administration/debug.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
# Debug Mathesar
# Debugging Mathesar

For now, we only support turning on Debugging by using our special docker image. More methods will follow in future releases.
If your Mathesar installation isn't working as expected, you can use our `mathesar-debug` Docker image that adds more debugging output to the console and more verbose errors in the browser when something goes wrong. The additional information logged should help you or the Mathesar team diagnose the installation issue.

## Use the debugging Mathesar docker image

There is a debugging-enabled Mathesar docker image available at `mathesar/mathesar-debug` that is the same as the `mathesar/mathesar` image, except that it has more debugging output available in the console where it's run, and it also produces more verbose errors in the browser when something goes wrong.

You can use this image to figure out (or to help the Mathesar team figure out) what's wrong if your Mathesar installation isn't working as expected. The procedure is to
The debugging-enabled Mathesar docker image is available at the `mathesar/mathesar-debug` Docker repo. It's the same as the `mathesar/mathesar` image, other than adding more debugging output. To set it up:

1. Run Mathesar with the `mathesar/mathesar-debug` image, and then
1. Observe and report any additional output or clues to the Mathesar team.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Configuring Mathesar with environment variables
# Environment Variables for Configuration

This page contains all available environment variables supported by Mathesar. See the specific installation guides for the applicable environment variables and instructions on how to set them.

Expand All @@ -7,7 +7,7 @@ This page contains all available environment variables supported by Mathesar. Se

### `SECRET_KEY` {: #secret_key}

- **Description**: A unique random string used by Django for cryptographic signing ([see Django docs](https://docs.djangoproject.com/en/3.2/ref/settings/#std:setting-SECRET_KEY)). It helps Mathesar secure user sessions and encrypt saved PostgreSQL passwords.
- **Description**: A unique random string used by Django for cryptographic signing ([see Django docs](https://docs.djangoproject.com/en/4.2/ref/settings/#std:setting-SECRET_KEY)). It helps Mathesar secure user sessions and encrypt saved PostgreSQL passwords.
- **Format**: A 50 character string
- **Additional information**:

Expand All @@ -17,6 +17,13 @@ This page contains all available environment variables supported by Mathesar. Se
echo $(cat /dev/urandom | LC_CTYPE=C tr -dc 'a-zA-Z0-9' | head -c 50)
```
### `ALLOWED_HOSTS` {: #allowed_hosts}
- **Description**: A set of strings representing the host/domain names that Django is allowed to serve. This is a security measure to prevent HTTP Host header attacks ([see Django docs](https://docs.djangoproject.com/en/4.2/ref/settings/#allowed-hosts)).
- **Format**: A set of host/domain names separated by a comma
- **Default value**: `.localhost,127.0.0.1,[::1]`
## Internal Database configuration {: #db}
!!!info
Expand All @@ -25,27 +32,27 @@ This page contains all available environment variables supported by Mathesar. Se
### `POSTGRES_DB`
- **Description**: Specifies a name for the database that will be created and used by Mathesar for managing internal data.
- **Default value**: mathesar_django
- **Default value**: `mathesar_django`
### `POSTGRES_USER`
- **Description**: Specifies creation of a user with superuser privileges and a database with the same name.
- **Default value**: mathesar
- **Default value**: `mathesar`
### `POSTGRES_PASSWORD`
- **Description**: Specifies the superuser password that is required to be set for the PostgreSQL docker image.
- **Default value**: mathesar
- **Default value**: `mathesar`
### `POSTGRES_HOST`
- **Description**: Specifies the host name on which portgres listen for connections from client applications.
- **Default value**: mathesar_db
- **Default value**: `mathesar_db`
### `POSTGRES_PORT`
- **Description**: Specifies the port on which portgres listen for connections from client applications.
- **Default value**: 5432
- **Default value**: `5432`
## Caddy reverse proxy configuration {: #caddy}
Expand Down
Loading

0 comments on commit 54b2098

Please sign in to comment.