generated from pagopa/template-java-microservice
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
5 changed files
with
60 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
target/**/* | ||
.vscode | ||
/.idea/ | ||
emulatorcert.crt | ||
emulatorcert.crt | ||
.env |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
URI=https://localhost:8081 | ||
PRIMARY_KEY=C2y6yDjf5/R+ob0N8A7Cgv30VRDJIWEHLM+4QDU5DE2nQ9nDuVTqobD4b8mGGyPMbIZnqyMsEcaGQy67XIw/Jw== | ||
DB_NAME=db | ||
CONTAINER_NAMES=creditor_institutions,services | ||
PARTITION_KEYS=fiscalCode,transferCategory |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
from azure.cosmos import exceptions, CosmosClient, PartitionKey | ||
import os | ||
from dotenv import load_dotenv | ||
|
||
load_dotenv() | ||
|
||
URI = os.getenv('URI') | ||
PRIMARY_KEY = os.getenv('PRIMARY_KEY') | ||
DB_NAME = os.getenv('DB_NAME') | ||
CONTAINER_NAMES = os.getenv('CONTAINER_NAMES') | ||
PARTITION_KEYS = os.getenv('PARTITION_KEYS') | ||
|
||
# Initialize the Cosmos client | ||
endpoint = URI | ||
key = PRIMARY_KEY | ||
|
||
# <create_cosmos_client> | ||
client = CosmosClient(endpoint, key) | ||
# </create_cosmos_client> | ||
|
||
# Create a database | ||
# <create_database_if_not_exists> | ||
database_name = DB_NAME | ||
database = client.create_database_if_not_exists(id=database_name) | ||
# </create_database_if_not_exists> | ||
|
||
# Create a container | ||
# Using a good partition key improves the performance of database operations. | ||
# <create_container_if_not_exists> | ||
container_names = CONTAINER_NAMES.split(',') | ||
partition_keys = PARTITION_KEYS.split(',') | ||
|
||
containers_infra = zip(container_names, partition_keys) | ||
|
||
for container in containers_infra: | ||
container = database.create_container_if_not_exists( | ||
id=container[0], # container name | ||
partition_key=PartitionKey(path=f"/{container[1]}"), | ||
offer_throughput=400 | ||
) | ||
# </create_container_if_not_exists> |
File renamed without changes.