Ian Costanzo
    • Create new note
    • Create a note from template
      • Sharing URL Link copied
      • /edit
      • View mode
        • Edit mode
        • View mode
        • Book mode
        • Slide mode
        Edit mode View mode Book mode Slide mode
      • Customize slides
      • Note Permission
      • Read
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Write
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Engagement control Commenting, Suggest edit, Emoji Reply
    • Invite by email
      Invitee

      This note has no invitees

    • Publish Note

      Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

      Your note will be visible on your profile and discoverable by anyone.
      Your note is now live.
      This note is visible on your profile and discoverable online.
      Everyone on the web can find and read all notes of this public team.
      See published notes
      Unpublish note
      Please check the box to agree to the Community Guidelines.
      View profile
    • Commenting
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
      • Everyone
    • Suggest edit
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
    • Emoji Reply
    • Enable
    • Versions and GitHub Sync
    • Note settings
    • Note Insights New
    • Engagement control
    • Make a copy
    • Transfer ownership
    • Delete this note
    • Save as template
    • Insert from template
    • Import from
      • Dropbox
      • Google Drive
      • Gist
      • Clipboard
    • Export to
      • Dropbox
      • Google Drive
      • Gist
    • Download
      • Markdown
      • HTML
      • Raw HTML
Menu Note settings Note Insights Versions and GitHub Sync Sharing URL Create Help
Create Create new note Create a note from template
Menu
Options
Engagement control Make a copy Transfer ownership Delete this note
Import from
Dropbox Google Drive Gist Clipboard
Export to
Dropbox Google Drive Gist
Download
Markdown HTML Raw HTML
Back
Sharing URL Link copied
/edit
View mode
  • Edit mode
  • View mode
  • Book mode
  • Slide mode
Edit mode View mode Book mode Slide mode
Customize slides
Note Permission
Read
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Write
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Engagement control Commenting, Suggest edit, Emoji Reply
  • Invite by email
    Invitee

    This note has no invitees

  • Publish Note

    Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

    Your note will be visible on your profile and discoverable by anyone.
    Your note is now live.
    This note is visible on your profile and discoverable online.
    Everyone on the web can find and read all notes of this public team.
    See published notes
    Unpublish note
    Please check the box to agree to the Community Guidelines.
    View profile
    Engagement control
    Commenting
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    • Everyone
    Suggest edit
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    Emoji Reply
    Enable
    Import from Dropbox Google Drive Gist Clipboard
       Owned this note    Owned this note      
    Published Linked with GitHub
    • Any changes
      Be notified of any changes
    • Mention me
      Be notified of mention me
    • Unsubscribe
    # BC Registries Issuer Updates ## Existing BC Reg Issuer Process The existing BC Reg issuer jobs are descrbed [here](https://github.com/bcgov/von-bc-registries-agent/tree/master/data-pipeline). (The docs are a bit out of date but the overall architecture/approach hasn't changed.) The data is pulled from COLIN (old Oracle database) and generated credentials are posted to OrgBook. The event processor uses a postgres database to store "in process" and "posted" data. All python code dealing with reading the BC Reg database and loading data is [here](https://github.com/bcgov/von-bc-registries-agent/blob/master/data-pipeline/bcreg/bcregistries.py). All python code dealing with parsing the staged json data and generating credentials (and maintaining the event processor tables) is [here](https://github.com/bcgov/von-bc-registries-agent/blob/master/data-pipeline/bcreg/eventprocessor.py). The jobs are run using cron - there is a bunch of infrastructure based on [Mara Pipelines](https://github.com/mara/mara-pipelines) but it is not providing much value and we should consider re-factoring it out of existance someday. Basically the steps are (these run every 30 mintues in `prod`, and on request in `dev` and `test`): 1. Scan the source `events` table and determine what corps have been updated since the last run - update the [event_by_corp_filing](https://github.com/bcgov/von-bc-registries-agent/blob/master/data-pipeline/bcreg/eventprocessor.py#L209) table with a set of corps to be processed. The "event date" is used to determine what has been posted and what is new (there are multiple sources for the `event_id` so it is not sequential) - this is recorded in the [last_event](https://github.com/bcgov/von-bc-registries-agent/blob/master/data-pipeline/bcreg/eventprocessor.py#L188) table. 2. Load all data for each corp into a big json blob and store in the [corp_history_log](https://github.com/bcgov/von-bc-registries-agent/blob/master/data-pipeline/bcreg/eventprocessor.py#L253) table. All data is loaded into json, including the full history. 3. For each corp in the corp_history_log table, and based on the from/to events we are processing, create credentials to post to OrgBook and store in the [credential_log](https://github.com/bcgov/von-bc-registries-agent/blob/master/data-pipeline/bcreg/eventprocessor.py#L312) table. 4. Post credentials to OrgBook and update the status in the zzz table Each event processor table (xxx, yyy, zzz) has a set of fields to record the processing status (pending, processed or error). Data can be re-processed just by changing the status to pending. The credential staging table includes a hash of the credential to prevent duplicates getting posted to OrgBook. ## Updates Required to support the new LEAR Database Theoretically we just need to add new jobs for steps 1 and 2 above - if we load the same structure of json blob for the corporation then steps 3 and 4 will require probably minimal changes to deal with differences between the old COLIN and new LEAR databases. ### 1b. Monitor LEAR for updates We need to add a new job to monitor the new `transaction` table, and create two new tables in the event_processor database to record the status of LEAR corporation udpates: - `last_transaction` - similar to the existing `last_event`, record the last LEAR transaction processed. I believe we should use `filing_date` (not `transaction_id`) to record the latest processed transaction, which is consistent with how we currently process events - `transaction_by_corp_filing` - similar to the existing `event_by_corp_filing`, this will include a list of companies to process from LEAR (based on the transactions since the last update) We maintain a [list of company types](https://github.com/bcgov/von-bc-registries-agent/blob/master/data-pipeline/bcreg/eventprocessor.py#L83) to load from COLIN, we will need a corresponding list of company types to load from LEAR. As new company types are moved over we can maintain the types in these 2 lists. ## 2b. Load Corporation Data from LEAR There are a couple of options for this one. The current process is executed from [this function](https://github.com/bcgov/von-bc-registries-agent/blob/master/data-pipeline/bcreg/eventprocessor.py#L1876), which loops through all the companies identified in the previous step. That runs [this function](https://github.com/bcgov/von-bc-registries-agent/blob/master/data-pipeline/bcreg/eventprocessor.py#L1547), which is a bit convoluted because it is parametrized to run each processing step separately, or all steps together for each company. Eventually it calls [this function](https://github.com/bcgov/von-bc-registries-agent/blob/master/data-pipeline/bcreg/bcregistries.py#L1566) to load the data from BC Registries (COLIN) into a json blob, which is stored in the event processor database. As you can see, this just loads a json blob with the same structure of the underlying BC Reg database. ### Option 2b.1 - just modify the SQL statements When loading data from LEAR, just modify the SQL statements to map to the old COLIN column names - this is probably the easiest approach. For example, for this statement: ``` SELECT corp_num, corp_typ_cd, recognition_dts, last_ar_filed_dt, bn_9, bn_15, admin_email, last_ledger_dt FROM corporation WHERE corp_num = <some corp_num> ``` Use something like: ``` SELECT identifier as corp_num, legal_type as corp_typ_cd, founding_date as recognition_dts, null as last_ar_filed_dt, null as bn_9, bn_15 as bn_15, ? as admin_email, null as last_ledger_dt FROM business WHERE identifier = <some corp_num> ``` There will be some conditional logic, since not all COLIN fields are mapped to LEAR. Most significantly, the transaction effective date (event effective date in COLIN) is provided, so we don't need to migrate the convoluted set of logic we have for determining event effective dates. The BN_9 isn't provided (we post this to OrgBook) but we can get it from the BN_15 (substring first 9 digits). ### Option 2b.2 - change the logic when building the stored json object I think this makes less sense, as it is more work than just updating the SQL queries and doesn't provide additional value-add. For example in [this method](https://github.com/bcgov/von-bc-registries-agent/blob/master/data-pipeline/bcreg/bcregistries.py#L1478) (like many) doesn't even use the database column names and just uses the offset in the SQL result set. ### Option 2b.3 - generate a new json object base on the new LEAR table structure This would *also* require a new set of logic for step 3, which parses the json object and generated the credentials. I think this is probably best for long term, as we can ditch a lot of the "legacy" logic that is required to parse COLIN data, however my not be feasible to handle the initial company types that we are loading from LEAR.

    Import from clipboard

    Paste your markdown or webpage here...

    Advanced permission required

    Your current role can only read. Ask the system administrator to acquire write and comment permission.

    This team is disabled

    Sorry, this team is disabled. You can't edit this note.

    This note is locked

    Sorry, only owner can edit this note.

    Reach the limit

    Sorry, you've reached the max length this note can be.
    Please reduce the content or divide it to more notes, thank you!

    Import from Gist

    Import from Snippet

    or

    Export to Snippet

    Are you sure?

    Do you really want to delete this note?
    All users will lose their connection.

    Create a note from template

    Create a note from template

    Oops...
    This template has been removed or transferred.
    Upgrade
    All
    • All
    • Team
    No template.

    Create a template

    Upgrade

    Delete template

    Do you really want to delete this template?
    Turn this template into a regular note and keep its content, versions, and comments.

    This page need refresh

    You have an incompatible client version.
    Refresh to update.
    New version available!
    See releases notes here
    Refresh to enjoy new features.
    Your user state has changed.
    Refresh to load new user state.

    Sign in

    Forgot password

    or

    By clicking below, you agree to our terms of service.

    Sign in via Facebook Sign in via Twitter Sign in via GitHub Sign in via Dropbox Sign in with Wallet
    Wallet ( )
    Connect another wallet

    New to HackMD? Sign up

    Help

    • English
    • 中文
    • Français
    • Deutsch
    • 日本語
    • Español
    • Català
    • Ελληνικά
    • Português
    • italiano
    • Türkçe
    • Русский
    • Nederlands
    • hrvatski jezik
    • język polski
    • Українська
    • हिन्दी
    • svenska
    • Esperanto
    • dansk

    Documents

    Help & Tutorial

    How to use Book mode

    Slide Example

    API Docs

    Edit in VSCode

    Install browser extension

    Contacts

    Feedback

    Discord

    Send us email

    Resources

    Releases

    Pricing

    Blog

    Policy

    Terms

    Privacy

    Cheatsheet

    Syntax Example Reference
    # Header Header 基本排版
    - Unordered List
    • Unordered List
    1. Ordered List
    1. Ordered List
    - [ ] Todo List
    • Todo List
    > Blockquote
    Blockquote
    **Bold font** Bold font
    *Italics font* Italics font
    ~~Strikethrough~~ Strikethrough
    19^th^ 19th
    H~2~O H2O
    ++Inserted text++ Inserted text
    ==Marked text== Marked text
    [link text](https:// "title") Link
    ![image alt](https:// "title") Image
    `Code` Code 在筆記中貼入程式碼
    ```javascript
    var i = 0;
    ```
    var i = 0;
    :smile: :smile: Emoji list
    {%youtube youtube_id %} Externals
    $L^aT_eX$ LaTeX
    :::info
    This is a alert area.
    :::

    This is a alert area.

    Versions and GitHub Sync
    Get Full History Access

    • Edit version name
    • Delete

    revision author avatar     named on  

    More Less

    Note content is identical to the latest version.
    Compare
      Choose a version
      No search result
      Version not found
    Sign in to link this note to GitHub
    Learn more
    This note is not linked with GitHub
     

    Feedback

    Submission failed, please try again

    Thanks for your support.

    On a scale of 0-10, how likely is it that you would recommend HackMD to your friends, family or business associates?

    Please give us some advice and help us improve HackMD.

     

    Thanks for your feedback

    Remove version name

    Do you want to remove this version name and description?

    Transfer ownership

    Transfer to
      Warning: is a public team. If you transfer note to this team, everyone on the web can find and read this note.

        Link with GitHub

        Please authorize HackMD on GitHub
        • Please sign in to GitHub and install the HackMD app on your GitHub repo.
        • HackMD links with GitHub through a GitHub App. You can choose which repo to install our App.
        Learn more  Sign in to GitHub

        Push the note to GitHub Push to GitHub Pull a file from GitHub

          Authorize again
         

        Choose which file to push to

        Select repo
        Refresh Authorize more repos
        Select branch
        Select file
        Select branch
        Choose version(s) to push
        • Save a new version and push
        • Choose from existing versions
        Include title and tags
        Available push count

        Pull from GitHub

         
        File from GitHub
        File from HackMD

        GitHub Link Settings

        File linked

        Linked by
        File path
        Last synced branch
        Available push count

        Danger Zone

        Unlink
        You will no longer receive notification when GitHub file changes after unlink.

        Syncing

        Push failed

        Push successfully