https://github.com/manyakrus/ddl_from_protobuf
Create DDL sql script from protobuf .proto file, for database create tables and columns, constraints and indexes, generated automatic.
https://github.com/manyakrus/ddl_from_protobuf
ddl generator postgres postgresql protobuf script sql
Last synced: 7 months ago
JSON representation
Create DDL sql script from protobuf .proto file, for database create tables and columns, constraints and indexes, generated automatic.
- Host: GitHub
- URL: https://github.com/manyakrus/ddl_from_protobuf
- Owner: ManyakRus
- License: gpl-2.0
- Created: 2024-10-22T11:21:40.000Z (12 months ago)
- Default Branch: main
- Last Pushed: 2024-12-04T07:28:22.000Z (10 months ago)
- Last Synced: 2025-02-07T08:47:57.750Z (8 months ago)
- Topics: ddl, generator, postgres, postgresql, protobuf, script, sql
- Language: Go
- Homepage:
- Size: 4.48 MB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
The ddl_from_protobuf application is designed to create a DDL .sql file from protobuf .proto files
A text file is created with SQL query text for creating tables, etc.
SQL text for PostgreSQL databaseCan create:
- tables
- columns
- primary key
- constraints
- indexesIn .proto files, it finds all messages and enums, and creates DDL for them
For enum:
A table is created with the fields "id" and "name", primary key and index "id"
all values are filled in the rows (insert)For message:
Only messages that have a primary key are taken, i.e. a column with the name: "primary_key", "id", "uid"
A table with the name from messaage is created.
All columns that are in message are created, including:
- simple types
- references to enum tables
- references to message tables that have a primary key
- for references to message tables that do not have a primary key, many separate columns are created that are in the related table.
For columns of links to other tables, the suffix "_id" is added
Table and column names for SQL are formatted in the snake_case standard, in lowercase letters (since uppercase letters must be written in quotes)2) You can also generate the .go source code for converting from the Protobuf type to the Entities type for working with the database.
To do this, fill in the (.env) settings.txt file:
NEED_CREATE_CONVERT_FILES=true
REPOSITORY_PROTO_URL=Installation procedure:
1. Compile this repository
>make build
a ddl_from_protobuf file will appear in the bin folder2. Put protobuf .proto files in the bin/proto folder
3. Fill in the settings in the settings.txt (or .env) file
You can leave them blank, the default settings will be used4. Run
>ddl_from_protobuf
A new ddl.sql file will appear in the bin/proto folderSettings:
primary_key_names.json - you can change the list of field names for the primary key in the file
database_types.json - a table of type correspondences in protobuf and SQL
columns_every_table.sql - SQL test for adding to every table (empty)Source code in Golang.
Tested on Linux Ubuntu
Readme from 10/31/2024Made by Aleksandr Nikitin
https://github.com/ManyakRus/ddl_from_protobuf