Skip to content

Sub command: Tables

Faisal Ali edited this page Feb 23, 2020 · 6 revisions

Introduction

The table sub command is used to mock the data at table level, it also have option to create a random tables.

Short Hand: The short hand of the table subcommand is t

Usage

The usage of table subcommand is

[gpadmin@gpdb-m ~]$ mock tables --help
Creates fake tables, or mock tables with fake data

Usage:
  mock tables [flags]

Aliases:
  tables, t

Flags:
  -j, --case-sensitive-table-name   Table name with only lowercase or a mix of lower and uppercase
  -y, --column-name-prefix string   Prefix the mocked table columns with this name (default "mock_data")
  -c, --create-tables               Create fake tables in the database
  -h, --help                        help for tables
  -m, --max-table-columns int       Max number of columns that is needed i.e columns can be from 1 upto this max value (default 10)
  -t, --mock-tables string          Fake selected list of tables with fake data, to add in multiple tables use "," b/w table names
  -n, --num-tables int              How many fake tables is needed? (default 10)
  -s, --schema-name string          Under which schema do these fake tables need to be created or mocked? (default "public")
  -x, --table-name-prefix string    Prefix the mocked table with this name (default "mock_data")

Global Flags:
  -a, --address string    Hostname where the postgres database lives
  -d, --database string   Database to mock the data (default "gpadmin")
  -q, --dont-prompt       Run without asking for confirmation
  -i, --ignore            Ignore checking and fixing constraints
  -w, --password string   Password for the user to connect to database
  -p, --port int          Port number of the postgres database (default 3000)
  -r, --rows int          Total rows to be faked or mocked (default 10)
  -u, --username string   Username to connect to the database
  -v, --verbose           Enable verbose or debug logging

Example

Table Creation

  • To create fake tables
    mock tables --create-tables
    -- OR -- 
    mock t -c
    
  • To create fake tables in the schema let say "mocker"
    mock tables --create-tables --schema-name mocker
    -- OR -- 
    mock t -c -s mocker
    
  • To create 100 fake tables
    mock tables --create-tables --num-tables 100 
    -- OR -- 
    mock t -c -n 100
    
    100 fake tables
  • To create 20 fake tables with a mix of upper case and lower case table names
    mock tables --create-tables --num-tables 20 --case-sensitive-table-name 
    -- OR -- 
    mock t -c -n 20 -j
    
  • To create 20 fake tables with table name starting with "mocked_by_me"
    mock tables --create-tables --num-tables 20 --table-name-prefix mocked_by_me
    -- OR -- 
    mock t -c -n 20 -x mocked_by_me
    
  • To create 20 fake tables with number of column b/w 1 to 100
    mock tables --create-tables --num-tables 20 --max-table-columns 100
    -- OR -- 
    mock t -c -n 20 -m 100
    
  • To create 20 fake tables with number of column b/w 1 to 100 and column name prefixed with "random_column"
    mock tables --create-tables --num-tables 20 --max-table-columns 100 --column-name-prefix random_column
    -- OR -- 
    mock t -c -n 20 -m 100 -y random_column
    

Table Mocking

  • To fake data on the table say "actor"

    mock tables --mock-tables actor
    -- OR -- 
    mock t -t actor
    

    faking-into-single-table

  • To fake data on multiple table say "actor" & films

    mock tables --mock-tables actor,films
    -- OR -- 
    mock t -t actor,films
    
  • To fake data on the tables that belongs to a schema say "mocker"

    mock tables --mock-tables mocker.test1,mocker.test2
    -- OR -- 
    mock t -t mocker.test1,mocker.test2
    

    or you can use

    mock tables --mock-tables test1,test2 --schema-name mocker
    -- OR -- 
    mock t -t test1,test2 -s mocker
    

    faking-table-by-schema

  • To fake data on that tables with different schema, say "test1" & "test2" belongs to schema "mocker" and "actor" belongs to "public" schema

    mock tables --mock-tables mocker.test1,mocker.test2,public.actor
    -- OR -- 
    mock t -t mocker.test1,mocker.test2,public.actor
    

    or you can use

    mock tables --mock-tables test1,test2,public.actor --schema-name mocker
    -- OR -- 
    mock t -t test1,test2,public.actor -s mocker
    

    faking-multiple-schema-tables

  • To fake the amount of rows on the table

    mock tables --mock-tables actor --rows 100
    -- OR -- 
    mock t -t actor -r 100
    
Clone this wiki locally