-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: migrate models to postgres via pg-orm (#188)
- Loading branch information
Showing
89 changed files
with
1,555 additions
and
383 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 |
---|---|---|
@@ -0,0 +1,6 @@ | ||
Lint/NotNil: | ||
Enabled: false | ||
Style/PredicateName: | ||
Enabled: false | ||
Style/ParenthesesAroundCondition: | ||
Enabled: false |
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
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 @@ | ||
bin | ||
lib |
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,9 @@ | ||
root = true | ||
|
||
[*.cr] | ||
charset = utf-8 | ||
end_of_line = lf | ||
insert_final_newline = true | ||
indent_style = space | ||
indent_size = 2 | ||
trim_trailing_whitespace = true |
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 @@ | ||
/docs/ | ||
/lib/ | ||
/bin/ | ||
/.shards/ | ||
*.dwarf |
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,11 @@ | ||
FROM placeos/crystal:latest | ||
|
||
WORKDIR /app | ||
|
||
COPY . /app | ||
|
||
ENV PATH /app/bin:$PATH | ||
|
||
RUN shards build | ||
|
||
ENTRYPOINT [ "/app/run.sh" ] |
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 @@ | ||
MIT License | ||
|
||
Copyright (c) 2022 Ali Naqvi <[email protected]> | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
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,3 @@ | ||
#PlaceOS Models Migration Script | ||
|
||
This folder contains source code for scaffolding PlaceOS models schema and running migration. |
92 changes: 92 additions & 0 deletions
92
migration/db/migrations/20221103144813_add_doorkeeper_table.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,92 @@ | ||
-- +micrate Up | ||
-- SQL in section 'Up' is executed when this migration is applied | ||
|
||
-- Table for model Auth::OAuthApplications | ||
CREATE TABLE IF NOT EXISTS "oauth_applications"( | ||
id bigint PRIMARY KEY, | ||
name character varying NOT NULL, | ||
uid character varying NOT NULL, | ||
secret character varying NOT NULL, | ||
redirect_uri text NOT NULL, | ||
scopes character varying DEFAULT ''::character varying NOT NULL, | ||
confidential boolean DEFAULT true NOT NULL, | ||
owner_id text NOT NULL, | ||
created_at timestamp(6) without time zone NOT NULL, | ||
updated_at timestamp(6) without time zone NOT NULL | ||
); | ||
|
||
CREATE SEQUENCE public.oauth_applications_id_seq | ||
START WITH 1 | ||
INCREMENT BY 1 | ||
NO MINVALUE | ||
NO MAXVALUE | ||
CACHE 1; | ||
|
||
ALTER SEQUENCE public.oauth_applications_id_seq OWNED BY "oauth_applications".id; | ||
ALTER TABLE ONLY "oauth_applications" ALTER COLUMN id SET DEFAULT nextval('public.oauth_applications_id_seq'::regclass); | ||
CREATE UNIQUE INDEX index_oauth_applications_on_uid ON "oauth_applications" USING btree (uid); | ||
|
||
|
||
CREATE TABLE IF NOT EXISTS "oauth_access_grants" ( | ||
id bigint PRIMARY KEY, | ||
resource_owner_id TEXT NOT NULL, | ||
application_id bigint NOT NULL, | ||
token character varying NOT NULL, | ||
expires_in integer NOT NULL, | ||
redirect_uri text NOT NULL, | ||
created_at timestamp(6) without time zone NOT NULL, | ||
revoked_at timestamp(6) without time zone, | ||
scopes character varying DEFAULT ''::character varying NOT NULL | ||
); | ||
|
||
CREATE SEQUENCE public.oauth_access_grants_id_seq | ||
START WITH 1 | ||
INCREMENT BY 1 | ||
NO MINVALUE | ||
NO MAXVALUE | ||
CACHE 1; | ||
|
||
ALTER SEQUENCE public.oauth_access_grants_id_seq OWNED BY "oauth_access_grants".id; | ||
ALTER TABLE ONLY "oauth_access_grants" ALTER COLUMN id SET DEFAULT nextval('public.oauth_access_grants_id_seq'::regclass); | ||
CREATE INDEX index_oauth_access_grants_on_application_id ON "oauth_access_grants" USING btree (application_id); | ||
CREATE INDEX index_oauth_access_grants_on_resource_owner_id ON "oauth_access_grants" USING btree (resource_owner_id); | ||
CREATE UNIQUE INDEX index_oauth_access_grants_on_token ON "oauth_access_grants" USING btree (token); | ||
ALTER TABLE ONLY "oauth_access_grants" | ||
ADD CONSTRAINT fk_oauth_access_grants_on_oauth_applications_id FOREIGN KEY (application_id) REFERENCES "oauth_applications"(id); | ||
|
||
|
||
CREATE TABLE "oauth_access_tokens" ( | ||
id bigint PRIMARY KEY, | ||
resource_owner_id TEXT, | ||
application_id bigint NOT NULL, | ||
token character varying NOT NULL, | ||
refresh_token character varying, | ||
expires_in integer, | ||
revoked_at timestamp(6) without time zone, | ||
created_at timestamp(6) without time zone NOT NULL, | ||
scopes character varying, | ||
previous_refresh_token character varying DEFAULT ''::character varying NOT NULL | ||
); | ||
|
||
CREATE SEQUENCE public.oauth_access_tokens_id_seq | ||
START WITH 1 | ||
INCREMENT BY 1 | ||
NO MINVALUE | ||
NO MAXVALUE | ||
CACHE 1; | ||
|
||
ALTER SEQUENCE public.oauth_access_tokens_id_seq OWNED BY "oauth_access_tokens".id; | ||
ALTER TABLE ONLY "oauth_access_tokens" ALTER COLUMN id SET DEFAULT nextval('public.oauth_access_tokens_id_seq'::regclass); | ||
CREATE INDEX index_oauth_access_tokens_on_application_id ON "oauth_access_tokens" USING btree (application_id); | ||
CREATE UNIQUE INDEX index_oauth_access_tokens_on_refresh_token ON "oauth_access_tokens" USING btree (refresh_token); | ||
CREATE INDEX index_oauth_access_tokens_on_resource_owner_id ON "oauth_access_tokens" USING btree (resource_owner_id); | ||
CREATE UNIQUE INDEX index_oauth_access_tokens_on_token ON "oauth_access_tokens" USING btree (token); | ||
ALTER TABLE ONLY "oauth_access_tokens" | ||
ADD CONSTRAINT fk_oauth_access_tokens_on_oauth_applications_id FOREIGN KEY (application_id) REFERENCES "oauth_applications"(id); | ||
|
||
-- +micrate Down | ||
-- SQL section 'Down' is executed when this migration is rolled back | ||
|
||
DROP TABLE IF EXISTS "oauth_applications" | ||
DROP TABLE IF EXISTS "oauth_access_grants" | ||
DROP TABLE IF EXISTS "oauth_access_tokens" |
39 changes: 39 additions & 0 deletions
39
migration/db/migrations/20221103144834_add_condo_table.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,39 @@ | ||
-- +micrate Up | ||
-- SQL in section 'Up' is executed when this migration is applied | ||
|
||
CREATE TABLE "condo_uploads" ( | ||
id bigint PRIMARY KEY, | ||
user_id character varying, | ||
file_name character varying, | ||
file_size integer, | ||
file_id character varying, | ||
provider_namespace character varying, | ||
provider_name character varying, | ||
provider_location character varying, | ||
bucket_name character varying, | ||
object_key character varying, | ||
object_options text, | ||
resumable_id character varying, | ||
resumable boolean DEFAULT false, | ||
created_at timestamp(6) without time zone NOT NULL, | ||
updated_at timestamp(6) without time zone NOT NULL, | ||
file_path text, | ||
part_list character varying, | ||
part_data text | ||
); | ||
|
||
CREATE SEQUENCE public.condo_uploads_id_seq | ||
START WITH 1 | ||
INCREMENT BY 1 | ||
NO MINVALUE | ||
NO MAXVALUE | ||
CACHE 1; | ||
|
||
ALTER SEQUENCE public.condo_uploads_id_seq OWNED BY "condo_uploads".id; | ||
ALTER TABLE ONLY "condo_uploads" ALTER COLUMN id SET DEFAULT nextval('public.condo_uploads_id_seq'::regclass); | ||
|
||
|
||
-- +micrate Down | ||
-- SQL section 'Down' is executed when this migration is rolled back | ||
|
||
DROP TABLE IF EXISTS "condo_uploads" |
25 changes: 25 additions & 0 deletions
25
migration/db/migrations/20221103181928_add_api_key_table.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,25 @@ | ||
-- +micrate Up | ||
-- SQL in section 'Up' is executed when this migration is applied | ||
|
||
-- Table for model PlaceOS::Model::ApiKey | ||
CREATE TABLE IF NOT EXISTS "api_key"( | ||
created_at TIMESTAMPTZ NOT NULL, | ||
updated_at TIMESTAMPTZ NOT NULL, | ||
name TEXT NOT NULL, | ||
description TEXT NOT NULL, | ||
scopes JSONB NOT NULL, | ||
permissions INTEGER, | ||
secret TEXT NOT NULL, | ||
user_id TEXT, | ||
authority_id TEXT, | ||
id TEXT NOT NULL PRIMARY KEY | ||
); | ||
|
||
CREATE INDEX IF NOT EXISTS api_key_user_id_index ON "api_key" USING BTREE (user_id); | ||
CREATE INDEX IF NOT EXISTS api_key_authority_id_index ON "api_key" USING BTREE (authority_id); | ||
CREATE INDEX IF NOT EXISTS api_key_name_index ON "api_key" USING BTREE (name); | ||
|
||
-- +micrate Down | ||
-- SQL section 'Down' is executed when this migration is rolled back | ||
|
||
DROP TABLE IF EXISTS "api_key" |
30 changes: 30 additions & 0 deletions
30
migration/db/migrations/20221103181946_add_asset_table.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,30 @@ | ||
-- +micrate Up | ||
-- SQL in section 'Up' is executed when this migration is applied | ||
|
||
-- Table for model PlaceOS::Model::Asset | ||
CREATE TABLE IF NOT EXISTS "asset"( | ||
created_at TIMESTAMPTZ NOT NULL, | ||
updated_at TIMESTAMPTZ NOT NULL, | ||
name TEXT NOT NULL, | ||
category TEXT NOT NULL, | ||
description TEXT NOT NULL, | ||
purchase_date TIMESTAMPTZ NOT NULL, | ||
good_until_date TIMESTAMPTZ, | ||
identifier TEXT, | ||
brand TEXT NOT NULL, | ||
purchase_price INTEGER NOT NULL, | ||
images TEXT[] NOT NULL, | ||
invoice TEXT, | ||
quantity INTEGER NOT NULL, | ||
in_use INTEGER NOT NULL, | ||
other_data JSONB NOT NULL, | ||
parent_id TEXT, | ||
id TEXT NOT NULL PRIMARY KEY | ||
); | ||
|
||
CREATE INDEX IF NOT EXISTS asset_parent_id_index ON "asset" USING BTREE (parent_id); | ||
|
||
-- +micrate Down | ||
-- SQL section 'Down' is executed when this migration is rolled back | ||
|
||
DROP TABLE IF EXISTS "asset" |
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,27 @@ | ||
-- +micrate Up | ||
-- SQL in section 'Up' is executed when this migration is applied | ||
|
||
-- Table for model PlaceOS::Model::Repository | ||
CREATE TABLE IF NOT EXISTS "repo"( | ||
created_at TIMESTAMPTZ NOT NULL, | ||
updated_at TIMESTAMPTZ NOT NULL, | ||
name TEXT NOT NULL, | ||
description TEXT NOT NULL, | ||
folder_name TEXT NOT NULL, | ||
uri TEXT NOT NULL, | ||
commit_hash TEXT NOT NULL, | ||
branch TEXT NOT NULL, | ||
deployed_commit_hash TEXT, | ||
release BOOLEAN NOT NULL, | ||
username TEXT, | ||
password TEXT, | ||
repo_type INTEGER NOT NULL, | ||
id TEXT NOT NULL PRIMARY KEY | ||
); | ||
|
||
CREATE INDEX IF NOT EXISTS repo_folder_name_index ON "repo" USING BTREE (folder_name); | ||
|
||
-- +micrate Down | ||
-- SQL section 'Down' is executed when this migration is rolled back | ||
|
||
DROP TABLE IF EXISTS "repo" |
Oops, something went wrong.