Skip to content
Snippets Groups Projects
This project is mirrored from https://github.com/metabase/metabase. Pull mirroring updated .
  1. Jun 23, 2023
  2. Jun 22, 2023
  3. Jun 21, 2023
  4. Jun 20, 2023
    • Aleksandr Lesnenko's avatar
    • Maz Ameli's avatar
      Change "Data Model" to "Table Metadata" (#31132) · 73c640fd
      Maz Ameli authored
      * change Data Model to Table Metadata
      
      * update doc references to the page
      
      * change name of manage data model permission
      
      * fix lint error
      
      * fix tests
      Unverified
      73c640fd
    • Noah Moss's avatar
      Connection impersonation (#30714) · f85ccd77
      Noah Moss authored
      * initial prototype w/out statement count parameter
      
      * new approach
      
      * default-database-role driver method
      
      * migration for connection_impersonations table
      
      * conn impersonation model, API and tests
      
      * impersonation fetch and deletion endpoints
      
      * switch test to t2 with-temp
      
      * read conn impersonation settings from DB
      
      * fix merge issue
      
      * add impersonated key to data perms graph and treat it the same as full self-service access
      
      * include impersonated key in returned permissions graph
      
      * make sure impersonated graph passes StrictDataPerms validation
      
      * fix boolean logic
      
      * make sure impersonated keyword doesnt cause error when deleting gtaps
      
      * clear impersonations as necessary when perms graphs changes
      
      * add impersonation support for postgres
      
      * fix typo
      
      * make sure impersonation updates are a non-lazy seq
      
      * add impersonated-user? fn
      
      * fix impersonation api tests
      
      * fix snippet tests
      
      * fix build & exclude connection impersonations from serialization
      
      * switch a test to use t2.with-temp
      
      * add with-impersonations helper and util tests
      
      * move macro and add a connection impersonation driver-level test for postgres
      
      * fix rebase issue
      
      * more tests and code reorganization
      
      * add snowflake test
      
      * clarify comment
      
      * fix lint errors
      
      * fix final kondo error
      
      * reorganization
      
      * fix one test
      
      * fix lint errors
      
      * revert change to sql_jdbc.execute from bad merge
      
      * make sure perms for all users gets reset after conn impersonation tests
      
      * ignore exceptions when restoring perms
      
      * fix postgres test
      
      * refactor to address bryan's comment
      
      * add note about new methods to database changelog
      
      * driver method refactor
      Unverified
      f85ccd77
    • Ngoc Khuat's avatar
      Remove usage of `toucan.models` (#31682) · a09bf414
      Ngoc Khuat authored
      * lint rule to prevent using model/defomdel and clean up model.interface
      
      * remove models/do-post-select
      
      * no more mdb.u/primary-key
      Unverified
      a09bf414
  5. Jun 19, 2023
    • Mahatthana (Kelvin) Nomsawadi's avatar
      Merge Encourage admins to add a database to master (#31610) · 31951b43
      Mahatthana (Kelvin) Nomsawadi authored
      * Encourage admin users to connect to a database (#31210)
      
      * Encourage admin users to connect to a database
      
      * Only render either payment banner or database prompt banner
      
      Discussed here:
      https://metaboat.slack.com/archives/C057T1QTB3L/p1685549180307149?thread_ts=1685547913.580079&cid=C057T1QTB3L
      
      
      
      * Improve mobile view layout
      
      * Address review: Remove `withRouter` HoC
      
      * Address review: Remove optional chaining
      
      * Address review: Refactor a component's deprecated `shouldRender` property
      
      * Add an e2e test to cover happy path
      
      * Remove new translation in `aria-label`
      
      * Fix sticky parameter widgets when showing database prompt banner
      
      * Fix E2E tests
      
      * Address review: Add missing unit tests
      
      * Fix a failed E2E test from rebasing off `master` branch
      
      * Add analytics (#31470)
      
      * 2/x Add analytics
      
      * Fix a failed E2E test from merging code from master
      
      * Prevent rendering the database prompt banner when white labeling (#31471)
      
      * 3/x Convert enterpise settings selectors to TypeScript
      
      * Add missing enterprise settings selectors tests
      
      * Don't render db prompt banner when white labeling
      
      * Reorganize the test to make an EE test more standing out
      
      * Address review: Remove unused function
      
      * 4/x Follow up reviews and tests (#31545)
      
      * 4/x Address review: Simplify code structure
      
      * Address review: Fix variable name collision
      
      * Move logic to display database banner to a hook
      
      * Remove unnecessary await
      
      * Restructure AppBanner tests
      
      * Swap test position to match the defined test matrix
      
      * Address review: removed outdated comment
      
      * Address review: Make `useShouldShowDatabasePromptBanner` hook tests clearer
      
      * Address review: Make conditions easier to follow
      
      Co-authored-by: default avatarUladzimir Havenchyk <uladzimir.dev@gmail.com>
      Co-authored-by: default avatarKamil Mielnik <kamil@kamilmielnik.com>
      
      ---------
      
      Co-authored-by: default avatarUladzimir Havenchyk <uladzimir.dev@gmail.com>
      Co-authored-by: default avatarKamil Mielnik <kamil@kamilmielnik.com>
      
      * 5/x Add embedding tests (#31557)
      
      * 5/x Add embedding tests
      
      * Clean up: Fix a selector signature
      
      * Address review: Using existing utility
      
      * Ensures that embedding pages are loaded before asserting UI not existing
      
      * Ready to write PublicQuestion tests
      
      * Move public and signed embeds tests to unit tests
      
      * Removed outdated eslint comment
      
      ---------
      
      Co-authored-by: default avatarUladzimir Havenchyk <uladzimir.dev@gmail.com>
      Co-authored-by: default avatarKamil Mielnik <kamil@kamilmielnik.com>
      Unverified
      31951b43
  6. Jun 17, 2023
  7. Jun 16, 2023
    • Ngoc Khuat's avatar
      Rest of models to toucan2 :tada: (#31385) · 647181fc
      Ngoc Khuat authored
      * User to toucan2
      
      * Pulse to toucan2
      
      * PulseCard to toucan 2
      
      * PulseChannel and PulseChannelRecipient to toucan2
      
      * Query, QueryCache, QueryExecution to toucan2
      
      * Metric, Segment, MetricImportantField to toucan2
      
      * ParameterCard to toucan2
      
      * DataMigrations and FakeCard to toucan2
      
      * NativeQuerySnippet to toucan2
      Unverified
      647181fc
  8. Jun 15, 2023
  9. Jun 13, 2023
    • Tim Macdonald's avatar
      Restrict uploading to people with data access to DB (#31427) · dfcfe5e0
      Tim Macdonald authored
      * Restrict uploading to people with correct perms
      
      [Fixes #30322]
      Unverified
      dfcfe5e0
    • Kamil Mielnik's avatar
      Respect alphabetical order of collections in "Move" modal (#31355) · 750f1cfe
      Kamil Mielnik authored
      * Remove unused openCollection prop
      
      * Preserve collection sorting given by API in getExpandedCollectionsById
      - Fixes #31294
      
      * Use Collections.getListStatePath() to unhardcode the object path
      
      * Use CollectionId instead of any
      
      * Extract Collections.selectors.getCollectionList
      
      * Convert Collections selectors unit tests to TypeScript
      
      * Remove redundant selector
      
      * Add a unit test for Collections.selectorsgetExpandedCollectionsById
      
      * Use createMockCollection for all test collections
      - Use Partial<Collection> instead of MockCollection type
      
      * Add a test case for non-nested collections
      
      * Rename identifiers
      
      * Add a test suite for snippet collections
      
      * Fix SnippetCollections.selectors.getExpandedCollectionsById
      
      * Refactor tests
      
      * Refactor tests
      
      * Revert unit tests for selectors
      
      * Revert convert selectors to TypeScript
      
      * Add error support to setupCollectionsEndpoints
      
      * Introduce useCollectionsQuery
      
      * Fix tests
      
      * Add unit tests for preserving order of collections in ItemPicker
      
      * Make assertions more semantic
      
      * Allow mocking root collection
      - Make ROOT_COLLECTION object match Collection type
      
      * Add tests for preserving order in snippet collections list
      - fix case with an undefined snippet collections list
      
      * Update test case with data loading necessary for ItemPicker underneath the EditSandboxModal after updating selectors
      
      * Update test case with data loading necessary for ItemPicker underneath the AddToDashSelectDashModal after updating selectors
      
      * Rename useCollectionsQuery to useCollectionListQuery
      
      * Remove leftover fetchMock
      
      * Move error out of setupCollectionsEndpoints
      
      * Fix ModelDetailPage unit tests setup
      
      * Remove leftover fetchMocks
      
      * Revert changes to ROOT_COLLECTION constant
      - use createMockCollection
      
      * Fix typing
      
      * Remove dead link to Source Sans Pro font
      - it caused markdown check to fail during CI, this fixes it
      - it seems that the font has been removed from Google Fonts
      - users can still choose this font in Metabase settings
      - removal confirmation: https://metaboat.slack.com/archives/C5XHN8GLW/p1686320576992299?thread_ts=1686319384.637909&cid=C5XHN8GLW
      
      * Fix getExpandedCollectionsById selector
      
      * Revert adding useCollectionListQuery in unit tests
      Unverified
      750f1cfe
  10. Jun 12, 2023
  11. Jun 09, 2023
  12. Jun 08, 2023
  13. Jun 07, 2023
    • bryan's avatar
      Autoload instance analytics content (when EE and avaliable) (#31314) · 4cbbc961
      bryan authored
      * wip
      
      * fix caching behavior for audit db in database-id->connection-pool
      
      * test that caching behavior works as advertised
      
      - db->pooled-connection-spec always returns the same pool for audit-db
      - audit-db-id is not in the database-id->connection-pool cache
      
      * DISABLE audit db exposure through GET api/database
      
      * Lots of things
      
      - automagically loads instance analytics on app startup
      - TODO: logging in after that is bokred
      
      * add some logs / fix comment
      
      * remove internal_analytics resource
      
      * fix linter issues + update logging
      
      * add tests for existing and missing content
      
      - add test replica of content into test-resources
      
      * remove unused require
      
      * delete sample db + personal collection from test-resources
      
      * get instance_analytics resource off the resource path
      
      * point it to the proper IA resource
      
      * un-hotwire the change to show audit DB on GET /databases
      
      * fix test + lookup the right resource
      
      * remove creator_id references from instance_analytics export test data
      
      - get test feedback
      
      * Revert "remove creator_id references from instance_analytics export test data"
      
      This reverts commit 1aa9d4b1dad304ac0c6d88221f81432d78fc88f0.
      
      * fix tests
      
      * lint
      
      * fix tests
      
      * more test fixing
      
      * linter fix
      
      * revert yarn.lock
      
      * Look up the correct instance_analytics resource
      
      * cleanup comment in serialization/cmd.clj
      
      * silence noisy serialization import logs
      
      * remove a bunch of unused serialization files
      
      * rename Audit Database + docstring
      
      * rename audit database everywhere
      
      * Put the database and tables back
      
      * constrain tests to postgres
      
      * ignore ia data in a test
      Unverified
      4cbbc961
    • Jerry Huang's avatar
      Change email notification url to allow for non-Metabase users to unsubscribe from alerts (#30892) · efccf731
      Jerry Huang authored
      * initial commit
      
      * add require
      
      * update gen hash
      
      * fix test
      
      * add email logic to alerts
      
      * fix one test
      
      * test fix
      
      * re-add retry
      
      * fix test
      
      * add test
      
      * address comments
      
      * fix typo
      
      * fix test
      
      * fix test
      
      * update req
      Unverified
      efccf731
  14. Jun 06, 2023
    • bryan's avatar
      Force Audit DB sync + fix connection pool caching behavior (#31234) · 324bcb83
      bryan authored
      * wip
      
      * fix caching behavior for audit db in database-id->connection-pool
      
      * test that caching behavior works as advertised
      
      - db->pooled-connection-spec always returns the same pool for audit-db
      - audit-db-id is not in the database-id->connection-pool cache
      
      * DISABLE audit db exposure through GET api/database
      
      * Lots of things
      
      - automagically loads instance analytics on app startup
      - TODO: logging in after that is bokred
      
      * Revert "Lots of things"
      
      This reverts commit 7eb5d57b221e4a91298e9d90fc9ed3e13922aeef.
      
      * Ignore audit-db for the "We're taking a look at your database!" modal
      Unverified
      324bcb83
    • Ngoc Khuat's avatar
      Activity, LoginHistory, ViewLog, TaskHistory, PersistedInfo to toucan2 (#30690) · 32f58905
      Ngoc Khuat authored
      * Activity to toucan2
      
      * LoginHistory to toucan2
      
      * ViewLog to toucan2
      
      * TaskHistory to toucan2
      
      * PersistedInfo to toucan2
      Unverified
      32f58905
  15. Jun 05, 2023
    • Kyle Doherty's avatar
      Remove styled-system (#31306) · 050b4fd8
      Kyle Doherty authored
      * rip out styled-system usage
      
      * fix yarn type-check errors, replace space properties w/ className equivelants
      
      * find / replace space prop usage [ci skip]
      
      * find / replace use of hover styled-system prop [ci skip]
      
      * account for fontSize usage w/ Text component [ci skip]
      
      * use font-size and weight props for styling text
      
      * fix a few additional uses of color
      
      * fix lint
      
      * fix lint
      
      * fix dumb rebase mistake
      Unverified
      050b4fd8
  16. Jun 02, 2023
    • Maz Ameli's avatar
      New icons (#31096) · a1b09db0
      Maz Ameli authored
      
      * arrow_left
      
      * check mark
      
      * arrow_up and chevrons
      
      * add, close, contract, embed, expand, sort
      
      * change viewbox to 16
      
      * icons in +New menu, search, and sidebar toggle
      
      * info_outlined, connections or fk icon, and tweaks to x-ray suggestion icons
      
      * fix database icon
      
      * ellipsis, person, and tweak ellipsis size in collections sidebar
      
      * home, reference or book, pencil or edit, table
      
      * dashboard action icons, and remove reference to unused ClockIcon.jsx
      
      * question action icons and related component tweaks
      
      * larger icons on HomeModelCard on homepage
      
      * dashboard and add_to_dash
      
      * snippet and variables
      
      * all the chart type icons and some field type ones
      
      * mail and groups
      
      * make sidebar icons darker blue
      
      * fix add-your-data icon
      
      * filled mail icon and use it on events modal
      
      * stars
      
      * bolt and x-rays and a bunch more
      
      * granular, metric, revision history
      
      * arrows, formula, snippets
      
      * click, cloud, boolean, unpin
      
      * return, hourglass, popover
      
      * pause, ldap, burger
      
      * gear info list pin moon sum sun verified warning
      
      * fix size of row details modal icons
      
      * fix size of left nav icons
      
      * fix size on filter widgets and some selects
      
      * set default size to 16 to fix entity menu icons etc
      
      * fix pagination icons
      
      * size and color on ItemPicker
      
      * bump up database icon in /browse to 32px
      
      * /browse bolt icon size
      
      * find and remove instances of 14px size declarations
      
      * sql editor icons
      
      * sql expand/contract button alignment
      
      * collection breadcrumbs
      
      * remove two more size 14 declarations
      
      * viz selector
      
      * fix add icon in New button
      
      * fix size of ModelDetailLink
      
      * icon for question list empty state
      
      * get rid of model_framed icon
      
      * try to fix event tick icons, replace balloons with cake
      
      * standardize size of question footer actions
      
      * fix dinosaur
      
      * switch star_outline to star, and star to star_filled
      
      * fix notebook sort action
      
      * switch data picker from table2 to table
      
      * fix slack icon
      
      * restyle HomeXrayCard
      
      * fix List icon
      
      * fix sidebar toggle icon size
      
      * fix icon size in field picker popovers
      
      * fix summarize sidebar field type icons
      
      * fix summarize sidebar Add buttons
      
      * table heading sort icons
      
      * fix filter icon, resize button icons
      
      * bulk filters icons
      
      * admin datamodel icons sizing
      
      * fix datamodel metric and segment icons, and sort icon
      
      * dashboard interactivity sidebar close icon
      
      * get rid of grabber2
      
      * bookmark and question actions icon sizes
      
      * revert icon
      
      * Icons cleanup (#31147)
      
      * remove timeline event icon stroke
      
      * cleanup
      
      * add 16x16 viewbox to svgs that were missing it
      
      * add slack_colorized
      
      * correct the join_full_outer icon
      
      * timeline events, cleanup
      
      * fix broken icons
      
      * more cleanup
      
      * fix storybook
      
      * fix all types
      
      * add stories
      
      * try fixing arrow_split
      
      ---------
      
      Co-authored-by: default avatarMaz Ameli <maz@metabase.com>
      
      * fix specs
      
      * fix specs
      
      * remove unused icons
      
      * use constants
      
      * increase node memory allocation
      
      * bump for chromatic too
      
      * fixes
      
      * fix arrow_split icon
      
      * fix arrow_split path attributes
      
      * fix path again and fix sizing of drillthrough menu icons
      
      * more spec fixes
      
      * prettier
      
      ---------
      
      Co-authored-by: default avatarAleksandr Lesnenko <alxnddr@users.noreply.github.com>
      Co-authored-by: default avatarAleksandr Lesnenko <alxnddr@gmail.com>
      Unverified
      a1b09db0
    • Cam Saul's avatar
      Use MLv2 for metadata calculation in QP (part 1); make column name calculation... · d96c318d
      Cam Saul authored
      Use MLv2 for metadata calculation in QP (part 1); make column name calculation consistent with QP (#29583)
      
      * Simplified impl
      
      * Add #31266 test
      
      * Yay
      
      * Very nice
      
      * Test fixes
      
      * Fix Kondo warnings
      Unverified
      d96c318d
    • Cam Saul's avatar
      Ban `mt/with-temp` and replace usages with `t2.with-temp/with-temp` (#31235) · 15026099
      Cam Saul authored
      * Ban `tt/with-temp` and convert usages to Toucan 2
      
      * Ban `tt/with-temp*` and convert usages to Toucan 2
      
      * Revert changes not meant for this PR
      
      * Ban `mt/with-temp` and replace usages with `t2.with-temp/with-temp`
      
      * Fixes :wrench:
      
      
      
      * Fix indentation
      
      * fix syntax in models.secret_test
      
      ---------
      
      Co-authored-by: default avatarNgoc Khuat <qn.khuat@gmail.com>
      Unverified
      15026099
    • john-metabase's avatar
    • Cam Saul's avatar
      Ban `tt/with-temp*` and convert usages to Toucan 2 (#31233) · e01bcd33
      Cam Saul authored
      * Ban `tt/with-temp` and convert usages to Toucan 2
      
      * Ban `tt/with-temp*` and convert usages to Toucan 2
      
      * Revert changes not meant for this PR
      Unverified
      e01bcd33
  17. Jun 01, 2023
  18. May 31, 2023
  19. May 30, 2023
    • bryan's avatar
      Add type column to collections + hydrate dashboards and cards with it (#30994) · 5b64eafb
      bryan authored
      * add migration for typed collections
      
      * add hydration of collections to card+dashboard api
      
      - adds it for:
        - GET /api/question/:id
        - GET /api/dashboard/:id
      
      * fix test that checks for collection shape
      
      * get tests working with hydrated collection
      
      * typo fixes
      
      * fix more tests
      
      - PUT requests don't hydrate :collection
      
      * update tests to fix param_values {} vs nil inconsistencies
      Unverified
      5b64eafb
  20. May 29, 2023
  21. May 26, 2023
    • Ngoc Khuat's avatar
      Move logic to infer revision.description to BE (#30502) · edc969ce
      Ngoc Khuat authored
      
      * Dashboard Tab entity (#29802)
      
      * add dashboard tab entity
      
      * Dashboard tabs CRUD (#29861)
      
      * Dashboard tabs frontend (#30189)
      
      * rename `DashboardHeader.tsx` to `DashboardHeaderView` to avoid collision with `DashboardHeader.jsx`
      
      commit-id:7cdfd86a
      
      * add tabs to dash
      
      commit-id:d3c2fa74
      
      * improve code structure and other fixes
      
      * rename `dashboardtab_id` to `dashboard_tab_id`
      
      * remove explicit `position` logic
      
      * improve code quality
      
      * add renaming functionality
      
      * add two new tabs when creating first tab
      
      * hide tabs if there is only one
      
      * add unit test for `DashboardTabs` component
      
      * refactor
      
      * fix type errors
      
      * add `tabId` to text cards
      
      * add `tabId` to link cards
      
      * add `tabId` to action button
      
      * use disabled state when only one tab remains
      
      * refetch cards with filter value when changing tabs
      
      * add e2e test
      
      * fix broken e2e tests
      
      * add horizontal scrolling
      
      * fix unit test
      
      * fix create tab button being on right
      
      * fix performance issue when switching tabs
      
      * add `ttag` to `tabs.ts`
      
      * use `aria-label` in e2e test helper
      
      * fix type error after rebasing
      
      * making ordered_tabs optional for tests purposes
      
      * fix failing unit tests
      
      * fix failing e2e tests
      
      * fix flaky revision history e2e test
      
      * fix type error after merging feature branch with master and rebasing
      
      * fix revisions unit test
      
      * fix `ActionParmatersInputsForm.tsx` to stop `actions-on-dashboards.cy.spec.js` from flaking
      
      ---------
      
      Co-authored-by: default avatarNgoc Khuat <qn.khuat@gmail.com>
      
      * migrating revision logic to BE
      
      * handle description for multiple cards add/remove
      
      * test fixes
      
      * adds tests
      
      * make sures events are started so tests work
      
      * remove additional `:maybe` that was added while rebasing
      
      * add title and has_multile_changes to revision
      
      * fixes potential test flake
      
      * more tests
      
      * remove debug code
      
      * handles collection change description in card and dashboard
      
      * fixes fail to build
      
      * use backend for revision history (#30772)
      
      * use BE response for revision history
      
      * update `service.unit.spec.js`
      
      * sort revision and moderation events for question timeline
      
      * test fixes
      
      * create revision directly instead of via API to avoid flake
      
      * reverted to an earlier revision => reverted to an earlier version
      
      * translate the model name too
      
      * Rename functions:
      - diff-strs -> diff-strings
      - diff-strings -> diff-strings*
      - diff-strings* -> diff-string
      
      * move the diff to diff-strings*
      
      * use case instead of map for model-str->i18n-str
      
      * remove title from API response
      
      * do not translate test model
      
      * rename var `title_text` to `titleText`
      
      * address comments
      
      * stringify the display name
      
      * fix revert button not working
      
      * add loading wrapper to fix unit test
      
      * fix tests
      
      * fix type error
      
      * fix QuestionActivityTimeline test
      
      * add a dot for edited this
      
      ---------
      
      Co-authored-by: default avatarEmmad Usmani <emmadusmani@berkeley.edu>
      Unverified
      edc969ce
  22. May 25, 2023
    • bryan's avatar
      Ensure smooth audit-db syncs for h2, postgres, and mysql (#30885) · 7aa00451
      bryan authored
      * fix h2 audit db syncs
      
      - typo: s/default-admin-db-id/default-audit-db-id/g
      - print db id without locale settings in `name-for-logging`
        - we probably never had a database with and id > 1000, but it would
          print like "1,000" in logs.
      - remove 2 more `defendpoint-schema` forms
      
      * adds making sure creating spec for *application-db* doesn't fail
      
      * Fixes test to only run when ee-avaliable, and only check for no throwing
      
      - Also handle case where manuall deleting the database doesn't delete
        the matching permissions (the path aka object is the same)
      
      * linter fix
      
      * fix linter error over deprecated hx namespace
      
      * add some test logging
      
      * update requires
      
      * remove logging, continue testing:
      
      - db->pooled-connection-spec
      - connection-details->spec
      
      * make sure we call the right ensure-audit-db-installed!
      
      * use mbc/ensure-audit-db-installed! directly
      
      * clean up test ns + fix clj-kondo linting
      
      * tie audit-db creation to running ee edition
      Unverified
      7aa00451
    • Noah Moss's avatar
      SQL snippets permission fix (#30960) · 24594300
      Noah Moss authored
      * new function for checking native query perms
      
      * update snippet perms to check for native perms and sandboxing
      
      * switch to using with-redefs rather than modifying native perms directly to try to fix final tests
      
      * revert unneeded change
      
      * fix regex and add test for set-has-any-native--query-permissions?
      Unverified
      24594300
  23. May 24, 2023
    • Noah Moss's avatar
      Fix enterprise model loading (#30969) · 26eac5e8
      Noah Moss authored
      
      * fix enterprise model loading
      
      * docstrings and remove tap
      
      * bump ci
      
      * address comment
      
      * Update src/metabase/models.clj
      
      Co-authored-by: default avatarmetamben <103100869+metamben@users.noreply.github.com>
      
      ---------
      
      Co-authored-by: default avatarmetamben <103100869+metamben@users.noreply.github.com>
      Unverified
      26eac5e8
    • Ryan Laurie's avatar
      Indexed Entities (#30487) · 7f51f3c9
      Ryan Laurie authored
      * indexed entities schema
      
      * schema
      
      * endpoint with create and delete
      
      * hooked up tasks
      
      * first tests and hooking it all together
      
      * some e2e tests
      
      * search
      
      * search
      
      had to rename value -> name. The search stuff works well for stuff that
      looks the same. And previously was renaming `:value` to name in the
      search result, but it uses the searchable-columns-for-model for which
      values to score on and wasn't finding :value. So easier to just let name
      flow through.
      
      * include model_pk in results
      
      * send pk back as id, include pk_ref
      
      * rename fk constraint (had copied it)
      
      * populate indexed values with name not value
      
      * GET http://localhost:3000/api/model_index?model_id=135
      
      * populate indexed values on post
      
      done here for ease of demo. followup work will schedule the task
      immediately, but for now, do it on thread and return info
      
      * test search results
      
      * fix t2 delete syntax on h2
      
      * fix h2
      
      * tests work on h2 and postgres app dbs
      
      * Fix after insert method
      
      after method lets you change the data. and i was returning the results
      of the refresh job as the model-index. not great
      
      * unify some cross-db logic for inserting model index values
      
      * Extract shared logic in populating indexed values; mysql support
      
      * clean ns
      
      * I was the bug (endpoint returns the item now)
      
      * fix delete to check perms on model not model-index
      
      * fix tests
      
      * Fix tests
      
      * ignore unused private var
      
      * Add search tests
      
      * remove tap>
      
      * Tests for simple mbql, joined mbql, native
      
      * shutdown scheduler after finishing
      
      * Entity Search + Indexing Frontend (#30082)
      
      * add model index types and mocks
      
      * add integer type check
      
      * add new entities for model indexes
      
      * expose model index toggle in model metadata
      
      * add search description for indexed entities
      
      * add an error boundary to the app bar
      
      * e2e test entity indexes
      
      * update tests and types
      
      * first tests and hooking it all together
      
      * Renumber migrations
      
      i forgot to claim them and i am a bad person
      
      * Restore changes lost in the rebase
      
      * add sync task to prevent errors in temp
      
      without this you get errors when the temp db is created as it wants to
      set the sync and analyze jobs but those jobs haven't been started.
      
      * Restore and test GET model-index/:model_id
      
      * clean up api: get by model id or model-index-id
      
      * update e2e tests
      
      * ensure correct types on id-ref and value-ref
      
      * simplify lookup
      
      * More extensive testing
      
      * update types
      
      * reorder migrations
      
      * fix tests
      
      * empty to trigger CI
      
      * update types
      
      * Bump clj-kondo
      
      old version reports
      
      /work/src/metabase/models/model_index.clj:27:6: error: #'metabase.models.interface/add-created-at-timestamp is private
      
      on source:
      
      ```clojure
      (t2/define-before-insert ::created-at-timestamp
        [instance]
        #_{:clj-kondo/ignore [:private-call]} ;; <- ignores this override
        (#'mi/add-created-at-timestamp instance))
      ```
      
      * Move task assertions to model namespace
      
      the task system is initialized in the repl so these all work
      locally. But in CI that's not necessarily the case. And rather than
      mocking the task system again I just leave it in the hands of the other
      namespace.
      
      * Don't serialize ModelIndex and ModelIndexValue
      
      seems like it is a setting on an individual instance. No need to have
      that go across boundaries
      
      * Just test this on h2.
      
      chasing names across the different dbs is maddening. and the underlying
      db doesn't really matter
      
      * indexes on model_index tables
      
      - `model_index.model_id` for searching by model_id
      - `model_index_value.model_index_id` getting values for a particular
        index
      
      * copy/paste error in indexing error message
      
      * `mt/with-temp` -> `t2.with-temp/with-temp`
      
      * use `:hook/created-at-timestamped?`
      
      * move field-ref normalization into models.interface
      
      * nit: alignment
      
      * Ensure write access to underlying model for create/delete
      
      * Assert more about pk/value refs and better error messages
      
      * Don't search indexed entities when user is sandboxed
      
      Adds a `= 1 0` clause to indexed-entity search if the user is
      sandboxed.
      
      Also, got tired of the pattern:
      
      ```clojure
      (if-let [segmented-user? (resolve 'metabase-enterprise.sandbox.api.util/segmented-user?)]
        (if (segmented-user?)
          :sandboxed-user
          :not-sandboxed-user)
        :not-sandboxed-user)
      ```
      
      and now we have a tasty lil ole'
      
      ```clojure
      (defenterprise segmented-user?
        metabase-enterprise.sandbox.api.util
        []
        false)
      ```
      
      that you can just
      
      ```clojure
      (ns foo
        (:require
         [metabase.public-settings.premium-features :as premium-features]))
      
      (if (premium-features/segmented-user?)
        :sanboxed
        :not-sandboxed)
      ```
      
      * redef premium-features/segmented-user?
      
      * trigger CI
      
      * Alternative GEOJSON.io fix (#30675)
      
      * Alternative GEOJSON.io fix
      
      rather than not testing, just accept that we might get an expected
      location back or we might get nil. This actually represents how the
      application will behave and will seamlessly work as the service improves
      or continues throwing errors:
      
      ```shell
      ❯ curl "https://get.geojs.io/v1/ip/geo.json?ip=8.8.8.8,136.49.173.73,185.233.100.23"
      <html>
      <head><title>500 Internal Server Error</title></head>
      <body>
      <center><h1>500 Internal Server Error</h1></center>
      <hr><center>openresty</center>
      </body>
      </html>
      
      ❯ curl "https://get.geojs.io/v1/ip/geo.json?ip=8.8.8.8,136.49.173.73"
      [{"area_code":"0","organization_name":"GOOGLE","country_code":"US",
        "country_code3":"USA","continent_code":"NA","ip":"8.8.8.8",
        "region":"California","latitude":"34.0544","longitude":"-118.2441",
        "accuracy":5,"timezone":"America\/Los_Angeles","city":"Los Angeles",
        "organization":"AS15169 GOOGLE","asn":15169,"country":"United States"},
       {"area_code":"0","organization_name":"GOOGLE-FIBER","country_code":"US",
       "country_code3":"USA","continent_code":"NA","ip":"136.49.173.73",
       "region":"Texas","latitude":"30.2423","longitude":"-97.7672",
       "accuracy":5,"timezone":"America\/Chicago","city":"Austin",
       "organization":"AS16591 GOOGLE-FIBER","asn":16591,"country":"United States"}]
      ```
      
      Changes are basically
      
      ```clojure
      (schema= (s/conditional some? <original-expectation-schema>
                              nil?  (s/eq nil)
               response-from-geojson)
      ```
      
      * Filter to login error messages
      
      ```clojure
      (into [] (map (fn [[log-level error message]] [log-level (type error) message]))
            error-messages-captured-in-test)
      [[:error
        clojure.lang.ExceptionInfo
        "Error geocoding IP addresses {:url https://get.geojs.io/v1/ip/geo.json?ip=127.0.0.1}"]
       [:error clojure.lang.ExceptionInfo "Authentication endpoint error"]]
       ```
      
      * check timestamps with regex
      
      seems like they fixed the service
      
      ```shell
      curl "https://get.geojs.io/v1/ip/geo.json?ip=8.8.8.8,136.49.173.73,185.233.100.23
      
      "
      [{"country":"United States","latitude":"34.0544","longitude":"-118.2441","accuracy":5,"timezone":"America\/Los_Angeles","ip":"8.8.8.8","organization":"AS15169 GOOGLE","country_code3":"USA","asn":15169,"area_code":"0","organization_name":"GOOGLE","country_code":"US","city":"Los Angeles","continent_code":"NA","region":"California"},{"country":"United States","latitude":"30.2423","longitude":"-97.7672","accuracy":5,"timezone":"America\/Chicago","ip":"136.49.173.73","organization":"AS16591 GOOGLE-FIBER","country_code3":"USA","asn":16591,"area_code":"0","organization_name":"GOOGLE-FIBER","country_code":"US","city":"Austin","continent_code":"NA","region":"Texas"},{"country":"France","latitude":"48.8582","longitude":"2.3387","accuracy":500,"timezone":"Europe\/Paris","ip":"185.233.100.23","organization":"AS198985 AQUILENET","country_code3":"FRA","asn":198985,"area_code":"0","organization_name":"AQUILENET","country_code":"FR","continent_code":"EU"}]
      ```
      
      whereas a few hours ago that returned a 500. And now the timestamps are different
      
      ```
      ;; from schema
      "2021-03-18T19:52:41.808482Z"
      ;; results
      "2021-03-18T20:52:41.808482+01:00"
      ```
      
      kinda sick of dealing with this and don't want to deal with a schema
      that matches "near" to a timestamp.
      
      * Restore these
      
      i copied changes over from tim's fix and it included these fixes. But
      now the service is fixed and these are the original values from cam's
      original fixes
      
      * Separate FK reference because of index
      
      ERROR in metabase.db.schema-migrations-test/rollback-test (ChangeLogIterator.java:126)
      Uncaught exception, not in assertion.
      
         liquibase.exception.LiquibaseException: liquibase.exception.RollbackFailedException: liquibase.exception.DatabaseException: (conn=637) Cannot drop index 'idx_model_index_model_id': needed in a foreign key constraint [Failed SQL: (1553) DROP INDEX `idx_model_index_model_id` ON `schema-migrations-test-db-32952`.`model_index`]
         liquibase.exception.RollbackFailedException: liquibase.exception.DatabaseException: (conn=637) Cannot drop index 'idx_model_index_model_id': needed in a foreign key constraint [Failed SQL: (1553) DROP INDEX `idx_model_index_model_id` ON `schema-migrations-test-db-32952`.`model_index`]
         liquibase.exception.DatabaseException: (conn=637) Cannot drop index 'idx_model_index_model_id': needed in a foreign key constraint [Failed SQL: (1553) DROP INDEX `idx_model_index_model_id` ON `schema-migrations-test-db-32952`.`model_index`]
         java.sql.SQLTransientConnectionException: (conn=637) Cannot drop index 'idx_model_index_model_id': needed in a foreign key constraint
           SQLState: "HY000"
          errorCode: 1553
      
      * delete cascade on model_index fk to report_card
      
      * reorder fk and index migrations
      
      * break apart FK from table definition for rollbacks
      
      * update types and appease the new lint rules
      
      * define models in a toucan2 way
      
      * remove checksum: ANY from migrations
      
      * api permissions 403 tests
      
      * test how we fetch values
      
      * remove empty line, add quotes to migration file
      
      * cleanup from tamas's comments
      
      - indention fix
      - inline an inc
      - add values in a tx (also catch errors and update model_index)
      - clarify docstring on `should-deindex?`
      - don't use declare, just define fn earlier
      
      * update after merge
      
      * update to new model name
      
      * only test joins for drivers that support it
      
      * don't test mongo, include scenario in test output
      
      * sets use `disj` not `dissoc`
      
      * handle oracle primary id type
      
      `[94M "Awesome Bronze Plate"]`
      (type 94M) -> java.math.BigDecimal
      
      * remove magic value of 5000 for threshold
      
      * Reorder unique constraint and remove extra index
      
      previously had a unique constraint (model_pk, model_index_id) and an
      index on model_index_id. If we reorder the unique constraint we get the
      index on the model_index_id for free. So we'll take it.
      
      * remove breakout.
      
      without breakout
      
      ```sql
       SELECT "source"."id"    AS "ID",
             "source"."title" AS "TITLE"
      FROM   (SELECT "PUBLIC"."products"."id"    AS "ID",
                     "PUBLIC"."products"."title" AS "TITLE"
              FROM   "PUBLIC"."products") AS "source"
      ORDER  BY "source"."title" DESC
      ```
      
      with breakout
      
      ```sql
       SELECT "source"."id"    AS "ID",
             "source"."title" AS "TITLE"
      FROM   (SELECT "PUBLIC"."products"."id"    AS "ID",
                     "PUBLIC"."products"."title" AS "TITLE"
              FROM   "PUBLIC"."products") AS "source"
      GROUP  BY "source"."id",
                "source"."title"
      ORDER  BY "source"."title" DESC,
                "source"."id" ASC
      ```
      
      * restore breakout
      
      caused some tests with joins to fail
      
      * update model-index api mock
      
      * Simpler method for indexing
      
      Remove the `generation` part. We'll do the set operations in memory
      rather than relying on db upserts. Now all app-dbs work the same and we
      get all indexed values, diff against current values from the model, and
      retract and add the appropriate values. "Updates" are counted as a
      retraction and then addition rather than separately trying to update a
      row.
      
      Some garbage generation stats:
      
      Getting garbage samples with
      
      ```clojure
      (defn tuple-stats
        []
        (let [x (-> (t2/query ["select n_live_tup, n_dead_tup, relname from pg_stat_all_tables where relname = 'model_index_value';"])
                    (first))]
          {:live (:n_live_tup x)
           :dead (:n_dead_tup x)}))
      ```
      
      And using a simple loop to index the values repeatedly:
      
      ```clojure
      (reduce (fn [stats _]
                (model-index/add-values! model-index)
                (conj stats (tuple-stats)))
              []
              (range 20))
      ```
      
      With generation style:
      
      ```clojure
      [{:live 200, :dead 0}
       {:live 200, :dead 0}
       {:live 200, :dead 0}
       {:live 200, :dead 400}
       {:live 200, :dead 400}
       {:live 200, :dead 400}
       {:live 200, :dead 400}
       {:live 200, :dead 770}
       {:live 200, :dead 770}
       {:live 200, :dead 787}
       {:live 200, :dead 787}
       {:live 200, :dead 825}
       {:live 200, :dead 825}
       {:live 200, :dead 825}
       {:live 200, :dead 825}
       {:live 200, :dead 818}
       {:live 200, :dead 818}
       {:live 200, :dead 818}
       {:live 200, :dead 818}
       {:live 200, :dead 854}]
      ```
      
      With "dump and reload":
      
      ```clojure
      [{:live 200, :dead 0}
       {:live 200, :dead 200}
       {:live 200, :dead 200}
       {:live 200, :dead 600}
       {:live 200, :dead 600}
       {:live 200, :dead 600}
       {:live 200, :dead 800}
       {:live 200, :dead 800}
       {:live 200, :dead 800}
       {:live 200, :dead 800}
       {:live 200, :dead 800}
       {:live 200, :dead 1600}
       {:live 200, :dead 1600}
       {:live 200, :dead 1600}
       {:live 200, :dead 2200}
       {:live 200, :dead 2200}
       {:live 200, :dead 2200}
       {:live 200, :dead 2200}
       {:live 200, :dead 2200}
       {:live 200, :dead 3600}]
      ```
      
      And of course now that it's a no-op,
      
      ```clojure
      [{:live 200, :dead 0}
       {:live 200, :dead 0}
       {:live 200, :dead 0}
       {:live 200, :dead 0}
       {:live 200, :dead 0}
       {:live 200, :dead 0}
       {:live 200, :dead 0}
       {:live 200, :dead 0}
       {:live 200, :dead 0}
       {:live 200, :dead 0}
       {:live 200, :dead 0}
       {:live 200, :dead 0}
       {:live 200, :dead 0}
       {:live 200, :dead 0}
       {:live 200, :dead 0}
       {:live 200, :dead 0}
       {:live 200, :dead 0}
       {:live 200, :dead 0}
       {:live 200, :dead 0}
       {:live 200, :dead 0}]
      ```
      
      Since no db actions have taken when reindexing. We've traded memory set
      operations for garbage in the database. Since we're capped at 5000 rows
      it seems fine for now.
      
      * add analogs to `isInteger` to constants.cljc and isa.cljc files
      
      * clarity and do less work on set conversion
      
      * exclude clojure.core/integer? from isa.cljc
      
      * Rename `state_change_at` -> `indexed_at`
      
      * breakout brings along an order-by and fields clause
      
      ---------
      
      Co-authored-by: default avatardan sutton <dan@dpsutton.com>
      Unverified
      7f51f3c9
  24. May 18, 2023
Loading