~ K    A     L    I ~
UNAME : Linux web63.extendcp.co.uk 4.18.0-553.56.1.el8_10.x86_64 #1 SMP Tue Jun 10 05:00:59 EDT 2025 x86_64
SERVER IP : 10.0.187.63 -________- CLIENT IP : 216.73.216.210
PATH :/bin/
UP FILE :
MINI SHELL D ZAB '
Current File : //bin/cdc_one_schema.py
#!/usr/bin/env python3

# Copyright (c) 2016 MariaDB Corporation Ab
# Copyright (c) 2023 MariaDB plc, Finnish Branch
#
# Use of this software is governed by the Business Source License included
# in the LICENSE.TXT file and at www.mariadb.com/bsl11.
#
# Change Date: 2025-09-12
#
# On the date above, in accordance with the Business Source License, use
# of this software will be governed by version 2 or later of the General
# Public License.

import json
import sys
import argparse

parser = argparse.ArgumentParser(description = """

This program generates a schema file for a single table by reading a tab
separated list of field and type names from the standard input.

To use this script, pipe the output of the `mysql` command line into the
`cdc_one_schema.py` script:

  mysql -ss -u <user> -p -h <host> -P <port> -e 'DESCRIBE `<database>`.`<table>`'|./cdc_one_schema.py <database> <table>

Replace the <user>, <host>, <port>, <database> and <table> with appropriate
values and run the command. Note that the `-ss` parameter is mandatory as that
will generate the tab separated output instead of the default pretty-printed
output.

An .avsc file named after the database and table name will be generated in the
current working directory. Copy this file to the location pointed by the
`avrodir` parameter of the avrorouter.

Alternatively, you can also copy the output of the `mysql` command to a file and
feed it into the script if you cannot execute the SQL command directly:

  # On the database server
  mysql -ss -u <user> -p -h <host> -P <port> -e 'DESCRIBE `<database>`.`<table>`' > schema.tsv
  # On the MaxScale server
  ./cdc_one_schema.py <database> <table> < schema.tsv

""", formatter_class=argparse.RawDescriptionHelpFormatter)
parser.add_argument("DATABASE", help="The database name where the table is located")
parser.add_argument("TABLE", help="The name of the table")

opts = parser.parse_args(sys.argv[1:])

def parse_field(row):
    res = dict()
    parts = row[1].lower().split('(')
    name = parts[0]

    res["real_type"] = name

    if len(parts) > 1 and name not in ["enum", "set", "decimal"]:
        res["length"] = int(parts[1].split(')')[0])
    else:
        res["length"] = -1

    type = "string"

    if name in ("date", "datetime", "time", "timestamp", "year", "tinytext", "text",
	        "mediumtext", "longtext", "char", "varchar", "enum", "set"):
        type = "string"
    elif name in ("tinyblob", "blob", "mediumblob", "longblob", "binary", "varbinary"):
        type = "bytes"
    elif name in ("int", "smallint", "mediumint", "integer", "tinyint", "short", "bit"):
        type = "int"
    elif name in ("float"):
        type = "float"
    elif name in ("double", "decimal"):
        type = "double"
    elif name in ("long", "bigint"):
        type = "long"

    res["type"] = ["null", type]

    res["name"] = row[0].lower()

    return res

try:
    schema = dict(namespace="MaxScaleChangeDataSchema.avro", type="record", name="ChangeRecord", fields=[])
    for line in sys.stdin:
        schema["fields"].append(parse_field(line.split('\t')))

    print("Creating: {}.{}.000001.avsc".format(opts.DATABASE, opts.TABLE))
    dest = open("{}.{}.000001.avsc".format(opts.DATABASE, opts.TABLE), 'w')
    dest.write(json.dumps(schema))
    dest.close()

except Exception as e:
    print(e)
    exit(1)

Coded by KALI :v Greetz to DR HARD ../ kali.zbi@hotmail.com