-
Notifications
You must be signed in to change notification settings - Fork 5
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: add migrations via atlas #59
Open
LiquidLemon
wants to merge
3
commits into
master
Choose a base branch
from
liquid/migrations
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 |
---|---|---|
@@ -0,0 +1 @@ | ||
migrations/atlas.sum binary |
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,10 @@ | ||
# Development | ||
|
||
## Migrations | ||
|
||
If you make changes to the database schema, you need to generate a new migration. | ||
To do this you need to install [atlas](https://atlasgo.io/). | ||
|
||
```shell | ||
atlas migrate diff --env=local <migration name> | ||
``` |
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,21 @@ | ||
data "external_schema" "peewee" { | ||
program = [ | ||
"helpers/db_schema.sh" | ||
] | ||
} | ||
|
||
env "local" { | ||
src = data.external_schema.peewee.url | ||
dev = "sqlite://dev?mode=memory" | ||
url = "sqlite://whoisdevices.db" | ||
|
||
migration { | ||
dir = "file://migrations" | ||
} | ||
|
||
format { | ||
migrate { | ||
diff = format("{{ sql . \" \" }}") | ||
} | ||
} | ||
} |
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,4 @@ | ||
#!/bin/bash | ||
export PYTHONPATH=. | ||
|
||
poetry run python whois/db_schema.py | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. is this wrapper needed? Maybe we can run it as a module |
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,19 @@ | ||
-- Create "device" table | ||
CREATE TABLE `device` ( | ||
`mac_address` char NOT NULL, | ||
`hostname` varchar NULL, | ||
`last_seen` datetime NOT NULL, | ||
`user_id` integer NULL, | ||
`flags` integer NULL, | ||
PRIMARY KEY (`mac_address`), | ||
CONSTRAINT `0` FOREIGN KEY (`user_id`) REFERENCES `user` (`id`) ON UPDATE NO ACTION ON DELETE NO ACTION | ||
); | ||
-- Create "user" table | ||
CREATE TABLE `user` ( | ||
`id` integer NOT NULL, | ||
`username` varchar NOT NULL, | ||
`password` varchar NOT NULL, | ||
`display_name` varchar NOT NULL, | ||
`flags` integer NULL, | ||
PRIMARY KEY (`id`) | ||
); |
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,2 @@ | ||
h1:EMRfUNLQLucjfPsImSG2fyQeY/BZRZ/LVYOtJAfHzf8= | ||
20240321230454_init.sql h1:+0SqLh3omTCq19IGAYbyECsORj2cicbwW9rOqVwh6VQ= |
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,14 @@ | ||
import peewee | ||
from playhouse.reflection import print_table_sql | ||
|
||
from whois.database import Device, User | ||
|
||
|
||
def print_schema(): | ||
for model in [Device, User]: | ||
print_table_sql(model) | ||
print(";") | ||
|
||
|
||
if __name__ == "__main__": | ||
print_schema() |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Either move everything related with development here from README or consolidate it with README file