CamilleTeruel commented on code in PR #5286:
URL: 
https://github.com/apache/incubator-devlake/pull/5286#discussion_r1206693473


##########
backend/core/utils/json.go:
##########
@@ -0,0 +1,67 @@
+/*
+Licensed to the Apache Software Foundation (ASF) under one or more
+contributor license agreements.  See the NOTICE file distributed with
+this work for additional information regarding copyright ownership.
+The ASF licenses this file to You under the Apache License, Version 2.0
+(the "License"); you may not use this file except in compliance with
+the License.  You may obtain a copy of the License at
+
+    http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/
+
+package utils
+
+import (
+       "fmt"
+       "reflect"
+
+       "github.com/apache/incubator-devlake/core/errors"
+)
+
+type JsonObject = map[string]any
+type JsonArray = []any
+
+func GetProperty[T any](object JsonObject, key string) (T, errors.Error) {
+       property, ok := object[key]
+       if !ok {
+               return *new(T), errors.Default.New(fmt.Sprintf("Missing 
property %s", key))
+       }
+       return convert[T](property)
+}
+
+func GetItem[T any](array JsonArray, index int) (T, errors.Error) {
+       if index < 0 || index >= len(array) {
+               return *new(T), errors.Default.New(fmt.Sprintf("Index %d out of 
range", index))
+       }
+       return convert[T](array[index])
+}
+
+func convert[T any](value any) (T, errors.Error) {

Review Comment:
   Done.



##########
backend/python/pydevlake/pydevlake/migration.py:
##########
@@ -0,0 +1,113 @@
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements.  See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You under the Apache License, Version 2.0
+# (the "License"); you may not use this file except in compliance with
+# the License.  You may obtain a copy of the License at
+
+#     http://www.apache.org/licenses/LICENSE-2.0
+
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+
+from typing import List, Literal, Optional, Union, Annotated
+from enum import Enum
+from datetime import datetime
+
+from pydantic import BaseModel, Field
+
+
+MIGRATION_SCRIPTS = []
+
+class Dialect(Enum):
+    MYSQL = "mysql"
+    POSTGRESQL = "postgres"
+
+
+class Execute(BaseModel):
+    type: Literal["execute"] = "execute"
+    sql: str
+    dialect: Optional[Dialect] = None
+
+
+class DropColumn(BaseModel):
+    type: Literal["drop_column"] = "drop_column"
+    table: str
+    column: str
+
+
+class DropTable(BaseModel):
+    type: Literal["drop_table"] = "drop_table"
+    table: str
+
+
+Operation = Annotated[
+    Union[Execute, DropColumn, DropTable],
+    Field(discriminator="type")
+]
+
+
+class MigrationScript(BaseModel):
+    operations: List[Operation]
+    version: int
+    name: str
+
+
+class MigrationScriptBuilder:
+    def __init__(self):
+        self.operations = []
+
+    def execute(self, sql: str, dialect: Optional[Dialect] = None):
+        """
+        Executes a raw SQL statement.
+        If dialect is specified the statement will be executed only if the db 
dialect matches.
+        """
+        self.operations.append(Execute(sql=sql, dialect=dialect))
+
+    def drop_column(self, table: str, column: str):
+        """
+        Drops a column from a table.
+        """
+        self.operations.append(DropColumn(table=table, column=column))
+
+    def drop_table(self, table: str):
+        """
+        Drops a table.
+        """
+        self.operations.append(DropTable(table=table))
+
+
+def migration(version: int):

Review Comment:
   Done.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to