# Create and modify a database
All functionality to create and modify a database structure is combined in the
`Factory` class.

## Create a new DB
```python
from duckatoms import Factory
factory = Factory('<path_to_db_file>/<db_name>.duckdb')
factory.create()
```
This generates a database with the minimal required properties to add atomic
structures.

## Modify an existing DB
1) Use the `Factory` class instance from the database creation or instantiate a
`Factory` class with the path to an existing database file.
```python
factory = Factory('<path_to_db_file>/<db_name>.duckdb')
```
2) Inspect what properties (aka columns) your database contains with:
```python
factory.show_db_structure()
```
3) Add properties to your *structures* or *atoms* table like coordination
number or mace descriptor with:
```python
# add coordination number
factory.add_property(table_name='atoms', property_name='o_coordination_number', property_dtype='INTEGER')

# add mace descriptor
factory.add_property(table_name='atoms', property_name='mace_descriptor', property_dtype='DOUBLE[128]')
```
To find the right datatype from Python to DuckDB take a look
[here](https://duckdb.org/docs/stable/clients/python/conversion).

4) To remove properties from the atoms table:
```python
factory.remove_property(table_name='atoms', property_name='o_coordination_number')
```
Keep in mind that deleting a property also deletes all its saved values.

Note: Properties from the *structures* table can't be removed. This is due to
the fact that *DuckDB* does not allow the removal of columns from a table whose
primary key is referenced in another table as a foreign key. To keep the data
integrity, the *structure_id* is referenced as a foreign key in the atoms table.
If you really want to remove a column, you unfortunately have to create a new
database.
