Thiết lập mô hình PowerDesigner từ kịch bản cấu trúc dữ liệu MySQL

Xuất kịch bản cấu trúc$table.sql

Bước 1: File -> Reverse Engineer -> Database

Bước 2: Chọn DBMS phù hợp (ví dụ MySQL 5.0)

Chú thích: Trong trường hợp cần thiết, các kịch bản sau có thể được sử dụng để tối ưu hóa quy trình:

Kịch bản sao chép tên vào chú thích

Khi thiết kế模型 Physical Data Model (PDM) trong PowerDesigner, thông thường sẽ sử dụng tên Tiếng Việt cho trường NAME và Tiếng Anh cho trường CODE. Tuy nhiên, khi chú thích (Comment) đã tồn tại, việc thêm chú thích một lần nữa sẽ gây phiền toái. Kịch bản sau sẽ giúp sao chép tên vào chú thích:

' Script 1: Sao chép tên vào chú thích cho các bảng, cột và view
Option Explicit
ValidationMode = True
InteractiveMode = im_Batch

Dim mdl ' model hiện tại

' Lấy model hiện tại
Set mdl = ActiveModel
If mdl Is Nothing Then
    MsgBox "Không có model hiện tại"
ElseIf Not mdl.IsKindOf(PdPDM.cls_Model) Then
    MsgBox "Model hiện tại không phải là Physical Data Model"
Else
    ProcessFolder mdl
End If

Private Sub ProcessFolder(folder)
    Dim tab ' bảng hiện tại
    For Each tab In folder.tables
        If Not tab.isShortcut Then
            tab.comment = tab.name
            Dim col ' cột hiện tại
            For Each col In tab.columns
                col.comment = col.name
            Next
        End If
    Next

    Dim view ' view hiện tại
    For Each view In folder.Views
        If Not view.isShortcut Then
            view.comment = view.name
        End If
    Next

    ' Xử lý các thư mục子 cấp
    Dim subFolder ' thư mục phụ
    For Each subFolder In folder.Packages
        If Not subFolder.IsShortcut Then
            ProcessFolder subFolder
        End If
    Next
End Sub

Kịch bản sao chép chú thích vào tên

Khi sử dụng Reverse Engineer để tạo PDM từ cơ sở dữ liệu, tên và mã của các bảng фактически đều sử dụng mã. Để thay tên bằng chú thích Tiếng Việt từ cơ sở dữ liệu, sử dụng kịch bản sau:

' Script 2: Sao chép chú thích vào tên
Option Explicit
ValidationMode = True
InteractiveMode = im_Batch

Dim mdl ' model hiện tại
Set mdl = ActiveModel

If mdl Is Nothing Then
    MsgBox "Không có model hiện tại"
ElseIf Not mdl.IsKindOf(PdPDM.cls_Model) Then
    MsgBox "Model hiện tại không phải là Physical Data Model"
Else
    ProcessFolder mdl
End If

Private Sub ProcessFolder(folder)
    Dim tab ' bảng hiện tại
    For Each tab In folder.tables
        If Not tab.isShortcut Then
            tab.name = tab.comment
            Dim col ' cột hiện tại
            For Each col In tab.columns
                If col.comment <> "" Then
                    col.name = col.comment
                End If
            Next
        End If
    Next

    Dim view ' view hiện tại
    For Each view In folder.Views
        If Not view.isShortcut Then
            view.name = view.comment
        End If
    Next

    ' Xử lý các thư mục子 cấp
    Dim subFolder ' thư mục phụ
    For Each subFolder In folder.Packages
        If Not subFolder.IsShortcut Then
            ProcessFolder subFolder
        End If
    Next
End Sub

Kịch bản chuyển đổi chữ thường sang hoa (Ctrl+Shift+X)

Kịch bản này giúp chuyển đổi tên bảng, cột và các đối tượng khác từ chữ thường sang hoa trong model:

' Script: powerdesigner.ucase.VBs
' Tác dụng: Chuyển đổi tất cả tên bảng, cột và mã từ chữ thường sang hoa
' Cách sử dụng: Mở model Physical Data, chạy script

Dim model ' model hiện tại
Set model = ActiveModel

If model Is Nothing Then
    MsgBox "Không có model hiện tại"
ElseIf Not model.IsKindOf(PdPDM.cls_Model) Then
    MsgBox "Model hiện tại không phải là Physical Data Model"
Else
    ProcessTables model
    ProcessSequences model
End If

Sub ProcessSequences(folder)
    Dim sequence
    For Each sequence In folder.sequences
        sequence.name = UCase(sequence.name)
        sequence.code = UCase(sequence.code)
    Next
End Sub

Sub ProcessTables(folder)
    Dim table
    For Each table In folder.tables
        If Not table.IsShortcut Then
            ProcessTable table
        End If
    Next

    Dim subFolder
    For Each subFolder In folder.Packages
        ProcessTables subFolder
    Next
End Sub

Sub ProcessTable(table)
    Dim column
    For Each column In table.Columns
        column.name = UCase(column.name)
        column.code = UCase(column.code)
    Next

    table.name = UCase(table.name)
    table.code = UCase(table.code)
End Sub

Thẻ: PowerDesigner mysql Script

Đăng vào ngày 9 tháng 6 lúc 21:38