Skip to content

Commit

Permalink
Add more documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
emeric-martineau committed Aug 2, 2023
1 parent 9736960 commit 0c4b72a
Show file tree
Hide file tree
Showing 10 changed files with 378 additions and 66 deletions.
16 changes: 9 additions & 7 deletions config/metabase.spc
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
connection "metabase" {
plugin = "1024pix/metabase"
plugin = "metabase"

# Your metabase url
# Your metabase url (requiried)
# url = "https://localhost"

# Metabase credentials
# Username/password is required for requests. Required except if token (see after) is provided.
# This can also be set via the `METABASE_USER` and `METABASE_PASSWORD` environment variable.
# user = "my_user"
# password = "my_password"

# Or token
# token = xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx
# Token is required for requests. Required except if user/password (see before) is provided.
# This can also be set via the `METABASE_TOKEN` environment variable.
# token = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"

# Skip TLS verification
# tls_skip_verify = true
# Skip TLS verification, useful in local test. Optionnal.
# tls_skip_verify = false
}
85 changes: 77 additions & 8 deletions docs/tables/metabase_db.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,95 @@

List all databases of Metabase.

This table need to be use first cause all tables started with `metabase_db_xxx` need to know the database id.

No field required.

## Examples

### List all databases

```sql
select
SELECT
id,
name,
description
from
description,
is_full_sync,
is_sample,
cache_field_values_schedule,
metadata_sync_schedule,
caveats,
engine,
created_at,
updated_at,
native_permissions,
points_of_interest
FROM
metabase_db;
```

### Get one database
### Get one database by name

```sql
select
SELECT
id
name,
description
from
FROM
metabase_db
WHERE
name = 'Test';
```

Return:
```
+------+-------------+
| name | description |
+------+-------------+
| 7 | <null> |
+------+-------------+
```

### List all database use PostgreSQL

```sql
SELECT
engine
FROM
metabase_db
WHERE
engine = 'postgres';
```

### List all databases are not fully syncrhonized after a Meatabase crash

```sql
SELECT
name,
is_full_sync
FROM
metabase_db
WHERE
is_full_sync = false;
```

Return:
```
+-----------------+--------------+
| name | is_full_sync |
+-----------------+--------------+
| Test | false |
+-----------------+--------------+
```

### Ensure no database can be use with native SQL

For this, we list all database with `native_permissions` set `write`:
```sql
SELECT
name
FROM
metabase_db
where
id=15;
WHERE
native_permissions = 'write';
```
55 changes: 52 additions & 3 deletions docs/tables/metabase_db_feature.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,64 @@

List all features of one database of Metabase.

You must provide `db_id`. `db_id` is the database id from `metabase_db` table.

## Examples

### Get features of database
### Get all enabled features of database

In case of we use PostgreSQL database, we want kown all list of features are activated on this PostgreSQL database.

`feature` column contain the list of activated features.

```sql
WITH my_db AS (
SELECT
id,
name
FROM
metabase_db
WHERE name = 'Test'
)
SELECT
feature
FROM
metabase_db_feature,
my_db
WHERE
db_id = my_db.id;
```

Return:
```
+----------------------------------------+--------------------------------+
| feature | _ctx |
+----------------------------------------+--------------------------------+
| actions | {"connection_name":"metabase"} |
| nested-queries | {"connection_name":"metabase"} |
...
| case-sensitivity-string-filter-options | {"connection_name":"metabase"} |
| inner-join | {"connection_name":"metabase"} |
+-------+----------------------------------------+--------------------------------+
```

### Check if regex is enable on PostgreSQL database

```sql
select
*
count(*)
from
metabase_db_feature
where
db_id=15;
db_id=15 and
feature = 'regex';
```

Return:
```
+-------+
| count |
+-------+
| 1 |
+-------+
```
103 changes: 93 additions & 10 deletions docs/tables/metabase_db_table.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,109 @@

List all tables of one databases of Metabase.

You must provide `db_id`. `db_id` is the database id from `metabase_db` table.

## Examples

### List all tables of one database

```sql
select
WITH my_db AS (
SELECT
id,
name
FROM
metabase_db
WHERE name = 'Test'
)
SELECT
id,
db_id,
schema,
show_in_getting_started,
name,
description,
caveats,
created_at,
updated_at,
visibility_type,
display_name,
points_of_interest
FROM
metabase_db_table, metabase_db
WHERE
db_id = my_db.id;
```

Return:
```
+-----+-------+--------+-------------------------+----------+-------------+---------+---------------------------+---------------------------+-----------------+-----------------------------+--------------------+--------------------------------+
| id | db_id | schema | show_in_getting_started | name | description | caveats | created_at | updated_at | visibility_type | display_name | points_of_interest | _ctx |
+-----+-------+--------+-------------------------+----------+-------------+---------+---------------------------+---------------------------+-----------------+-----------------------------+--------------------+--------------------------------+
| 209 | 15 | public | false | table1 | <null> | <null> | 2023-05-31T11:00:48+02:00 | 2023-05-31T11:00:53+02:00 | <null> | This is my table | <null> | {"connection_name":"metabase"} |
| 223 | 15 | public | false | table2 | <null> | <null> | 2023-05-31T11:00:49+02:00 | 2023-05-31T11:00:52+02:00 | <null> | A amazing table | <null> | {"connection_name":"metabase"} |
| 201 | 15 | public | false | table3 | <null> | <null> | 2023-05-31T11:00:48+02:00 | 2023-05-31T11:00:52+02:00 | <null> | Another one bites the dust | <null> | {"connection_name":"metabase"} |
...
```

### Search table with special warning

```sql
WITH my_db AS (
SELECT
id as my_db_id,
name as my_db_name
FROM
metabase_db
WHERE name = 'Test'
)
SELECT
id,
db_id,
name,
caveats
FROM
metabase_db_table,
my_db
WHERE
db_id = my_db.my_db_id AND
caveats IS NOT NULL;
```

Return:
```
+----+-------+------+---------+
| id | db_id | name | caveats |
+----+-------+------+---------+
+----+-------+------+---------+
```

### Get one table of database

`id` is table id that you want.

```sql
SELECT
*
from
FROM
metabase_db_table
where
db_id=15;
WHERE
db_id=15 and id=209;
```

### Get table from one database
### List all tables show in getting started

```sql
select
*
from
SELECT
metabase_db_table.db_id as db_id,
metabase_db_table.id as table_id,
metabase_db_table.name as name
FROM
metabase_db_table
where
db_id=15 and id=7;
INNER JOIN
metabase_db ON metabase_db_table.db_id = metabase_db.id
WHERE
metabase_db_table.show_in_getting_started = true
ORDER BY
db_id ASC, table_id ASC;
```
50 changes: 39 additions & 11 deletions docs/tables/metabase_permission.md
Original file line number Diff line number Diff line change
@@ -1,25 +1,53 @@
# Table: metabase_permission

List all permissions of Metabase.
List all permissions from Metabase.

To understand how permision works, you can read official documentation of Metabase [](https://www.metabase.com/docs/latest/permissions/data).

`db_id` is the database id from `metabase_db` table.

`group_id` is Metabase group that you can find in `metabase_permission_group` table.

## Examples

### List all permissions

```sql
select
*
from
SELECT
group_id,
db_id,
download_native,
download_schema,
data_native,
data_schema
FROM
metabase_permission;
```

### Get permission of one group
Return:
```
+----------+-------+-----------------+-----------------+-------------+-------------+--------------------------------+
| group_id | db_id | download_native | download_schema | data_native | data_schema | _ctx |
+----------+-------+-----------------+-----------------+-------------+-------------+--------------------------------+
| 4 | 1 | <null> | <null> | <null> | limited | {"connection_name":"metabase"} |
| 2 | 5 | full | full | write | all | {"connection_name":"metabase"} |
...
```

### Display group name with permission

```sql
select
*
from
metabase_permission_group
where
group_id=15;
SELECT
group_id,
name,
db_id,
download_native,
download_schema,
data_native,
data_schema
FROM
metabase_permission
INNER JOIN metabase_permission_group ON metabase_permission_group.id = metabase_permission.group_id
ORDER BY
group_id;
```
Loading

0 comments on commit 0c4b72a

Please sign in to comment.